简体   繁体   English

modulenotfounderror:没有名为“ sklearn”的模块

[英]modulenotfounderror : no module named 'sklearn'

from sklearn import tree

In python, when I run this code in the interpreter, I get an error: 在python中,当我在解释器中运行此代码时,出现错误:

"modulenotfounderror : no module named 'sklearn'" “ modulenotfounderror:没有名为'sklearn'的模块”

How can I fix this problem? 我该如何解决这个问题? I can run this in IDLE version successfully. 我可以在IDLE版本中成功运行它。 But running the interpreter, it doesn't not work. 但是运行解释器,这是行不通的。

By default sklearn module is not pre-packaged with Pyhton. 默认情况下,sklearn模块未与Pyhton预先包装在一起。 You have to install sklearn module using pip. 您必须使用pip安装sklearn模块。

Run following command on python console for installing sklearn module: 在python控制台上运行以下命令以安装sklearn模块:

pip install sklearn 点安装sklearn

You can also install utility modules that helps sklearn module: 您还可以安装有助于sklearn模块的实用程序模块:

  • pip install numpy pip安装numpy
  • pip install scipy 点安装scipy

Please check which python version you use in the interpreter: 请检查您在解释器中使用的python版本:

which python or python --version which pythonpython --version

If it is not same with IDLE version, you have to set the environment path first. 如果与IDLE版本不同,则必须首先设置环境路径。 Because you mentioned .exe , here is the way to set up on Window machine. 因为您提到了.exe ,所以这里是在Window计算机上进行设置的方法。 Please write one of the following command into your command prompt. 请将以下命令之一写入命令提示符。 (It depends on which version you used in IDLE version.) (这取决于您在IDLE版本中使用的版本。)

set path=%path%;C:\\python36

set path=%path%;C:\\python27

C:\\python36 is where python installation is usually installed on Window machine. C:\\python36通常是在Windows计算机上安装python安装的位置。

From the command line, if you have multiple versions of python and want to use specified version of python, you can try py -2 or py -3 . 在命令行中,如果您有多个python版本,并且想要使用指定版本的python,则可以尝试py -2py -3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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