Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named sklearn.datasets

os: mac os yosemite
python: 2.7.6 -- 64-bit
installed: numpy,skipy,matplotlib,nose

I get the following error.

>>> from sklearn.datasets import load_iris

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named sklearn.datasets

$ pip install --user --install-option="--prefix=" -U scikit-learn
Requirement already up-to-date: scikit-learn in /Library/Python/2.7/site-packages
Cleaning up...

Someone help me please!

like image 484
pollseed Avatar asked Nov 14 '14 14:11

pollseed


3 Answers

export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages or export PYTHONPATH=$PYTHONPATH:'path where your installed modules are'

to find out the path where your modules are installed, try to run pip install again and it will output the location

like image 61
JackNova Avatar answered Oct 06 '22 00:10

JackNova


Ran into a similar problem recently and spent too much time googling it while the error was simple: my file was named sklearn.py It might be why your import is not working.

like image 21
Mehdi Bettiche Avatar answered Oct 06 '22 01:10

Mehdi Bettiche


When installing on Ubuntu Linux you have to have to install dependencies first using apt-get, then use a pip install otherwise the normal pip install of scikit-learn won't work properly. See below:

Step 1: Make sure apt-get is updated
sudo apt-get update

Step 2: Install dependencies
sudo apt-get install build-essential python-dev python-setuptools python-numpy python-scipy libatlas-dev libatlas3gf-base

Step 3: pip install Scikit Learn
pip install --user --install-option="--prefix=" -U scikit-learn

Hope this helps!

like image 40
Morgan Linton Avatar answered Oct 06 '22 01:10

Morgan Linton