Python 导入错误:没有名为 sklearn.preprocessing 的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29180951/
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
ImportError: No module named sklearn.preprocessing
提问by
I installed scikit-learn successfully on Ubuntu following these instructions.
我按照这些说明在 Ubuntu 上成功安装了 scikit-learn 。
However, I get this error when I run a program that uses it:
但是,当我运行使用它的程序时出现此错误:
Traceback (most recent call last):
File "begueradj.py", line 10, in <module>
from sklearn.preprocessing import normalize
ImportError: No module named sklearn.preprocessing
How do I fix this?
我该如何解决?
回答by Randy Coburn
normalize is a method of Preprocessing. Therefore you need to import preprocessing.
normalize 是一种预处理方法。因此,您需要导入预处理。
In your code you can then call the method preprocessing.normalize().
在您的代码中,您可以调用方法 preprocessing.normalize()。
from sklearn import preprocessing
preprocessing.normailze(x,y,z)
If you are looking to make the code short hand then you could use the import x from y as z syntax
如果您希望简化代码,那么您可以使用 import x from y as z 语法
from sklearn import preprocessing as prep
prep.normalize(x,y,z)
回答by Randy Coburn
The instructions given in that tutorial you linked to are obsolete for Ubuntu 14.04.
您链接到的该教程中给出的说明对于 Ubuntu 14.04 已过时。
The Ubuntu 14.04 package is named python-sklearn (formerly python-scikits-learn
):
Ubuntu 14.04 软件包名为 python-sklearn(以前称为python-scikits-learn
):
sudo apt-get install python-sklearn
The python-sklearn
package is in the default repositories in Ubuntu 14.04 as well as in other currently supported Ubuntu releases.
该python-sklearn
软件包位于 Ubuntu 14.04 以及其他当前支持的 Ubuntu 版本中的默认存储库中。
回答by Jhon
I resolved the issue by running this command in terminal:
我通过在终端中运行这个命令解决了这个问题:
sudo apt-get install python-sklearn