简体   繁体   中英

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!

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

最近遇到了类似的问题,花了太多时间在谷歌上搜索它,而错误很简单:我的文件名为sklearn.py这可能是您的导入不起作用的原因。

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!

sklearn I was sure that you have installed. So, after you create a symbolic link the sklearn to Python interpreter, it went well.

ln -s 'path of sklearn' 'path of python interpreter'

I had the same problem. I solved just writing:

from sklearn import datasets

data = datasets.load_iris()

Are you sure you're running the right Python? It may be that scikit-learn is only installed for Python3, and not Python 2, so you may need to run python3 my_code.py instead of just python my_code.py .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM