Python 导入错误:没有名为 sklearn.datasets 的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26932445/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 01:11:12  来源:igfitidea点击:

ImportError: No module named sklearn.datasets

pythonscipyscikit-learn

提问by pollseed

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

操作系统:mac os yosemite
python:2.7.6 -- 64 位
安装: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!

请有人帮助我!

回答by pollseed

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

sklearn 我确定你已经安装了。因此,在您创建 sklearn 到 Python 解释器的符号链接后,一切顺利。

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

回答by HymanNova

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

export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages 或 export PYTHONPATH=$PYTHONPATH:'安装模块所在的路径'

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

要找出安装模块的路径,请尝试再次运行 pip install ,它将输出位置

回答by Morgan Linton

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:

在 Ubuntu Linux 上安装时,您必须首先使用 apt-get 安装依赖项,然后使用 pip install 否则 scikit-learn 的正常 pip 安装将无法正常工作。见下文:

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

第 1 步:确保 apt-get 已更新
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

第二步:安装依赖
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

第三步:pip install Scikit Learn
pip install --user --install-option="--prefix=" -U scikit-learn

Hope this helps!

希望这可以帮助!

回答by Mehdi Bettiche

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

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

回答by Caterina De Franco

I had the same problem. I solved just writing:

我有同样的问题。我解决了只写:

from sklearn import datasets

data = datasets.load_iris()