Issue
I just installed sklearn, my program runs no problem when I import it into the code. However, whenever I try to access the naive_bayes
module, I get this error:
ImportError: No module named naive_bayes
Here's how I'm importing it:
from sklearn.naive_bayes import GaussianNB
Not sure where I'm going wrong, any help is much appreciated!
Solution
In the spirit of "turn it off, and turn it back on again" solutions, and given the fact that you're getting a Module has no attribute: __version__
when you try and print the scikit-learn version (which should be defined in any self-respecting Python module), I'm going to recommend you uninstall and reinstall scikit-learn:
pip uninstall sklearn
pip install sklearn
Run the following commands, and compare to the output provided, to make sure the package is behaving the way it should:
>>> import sklearn
>>> print(sklearn.__version__)
0.19.0
>>> print(sklearn.__file__)
/usr/local/lib/python3.6/site-packages/sklearn/__init__.py
>>>
The output from printing sklearn.__file__
does not need to match exactly, but it should at least print some location on your computer.
Also, check to make sure your pip
matches your python
. This depends on what platform you're on, but this mix of version 2 and version 3 sometimes creates a nasty cocktail. Executing pip --version
should tell you which version of Python it is tied to.
$ which pip3
/usr/local/bin/pip3
$ pip3 --version
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)
$ which python3
/usr/local/bin/python3
You should be OK with Python version 2, so long as things match.
(Soap box moment: move to Python 3 if you don't have a really good reason for sticking with Python 2!)
Answered By - charlesreid1
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.