导入错误:没有名为 sklearn 的模块(Python)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36404042/
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 17:50:20  来源:igfitidea点击:

ImportError: No module named sklearn (Python)

pythonmacosscikit-learn

提问by Lorenzo Vannucchi

I wanna use scikit-learn. I have typed

我想使用 scikit-learn。我已经打字

pip install -U scikit-learn
pip3 install sklearn

to install it; but when i type

安装它;但是当我打字的时候

$ Python
>>> import sklearn

it returns

它返回

ImportError: No module named sklearn

I followed other tutorials, but it doesn't work. Furthermore, my enviroment returns this warning:

我跟着其他教程,但它不起作用。此外,我的环境返回此警告:

If you have installed scikit-learn from source, please do not forget to build the package before using it: run python setup.py installor makein the source directory.

如果您已经从源代码安装了 scikit-learn,请不要忘记在使用它之前构建包:运行python setup.py installmake在源目录中。

What is the true code to type in the terminal? I tried to type python setup.py installin the terminal but it doesn't work

在终端中输入的真实代码是什么?我试图python setup.py install在终端中输入但它不起作用

采纳答案by Igor Fil

Make sure that pip and python are the same version. For example if you run pip for python 2.7, it will install the package only in 2.7, and if your python command point to for example python 3.3 interpreter, it will not have that package

确保 pip 和 python 是相同的版本。例如,如果您为 python 2.7 运行 pip,它只会在 2.7 中安装包,并且如果您的 python 命令指向例如 python 3.3 解释器,它将没有该包

回答by abdellah el atouani

you dont have the package scikit-learn installed, try this if you are in a terminal linux :

你没有安装 scikit-learn 包,如果你在终端 linux 中试试这个:

sudo pip install scikit-learn

if you want to install the package within your code use

如果要在代码中安装包,请使用

import os 
os.system('sudo pip install scikit-learn')

回答by Haider Rizvi

Try:

尝试:

pip3 install scikit-learn

回答by user3409586

Not only for this package but also for almost cases, please try using python3 -m pip install sklearnif pip install sklearndoes not work.

不仅对于这个包,而且对于几乎所有情况,请尝试使用python3 -m pip install sklearnifpip install sklearn不起作用。

回答by Sean

I think you havent install sklearn, try this on your python terminal:

我想你还没有安装 sklearn,在你的 python 终端上试试这个:

pip install sklearn

and proceed with your code

并继续您的代码