Python ModuleNotFoundError:没有名为“sklearn”的模块

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

ModuleNotFoundError: No module named 'sklearn'

pythonanaconda

提问by Hareez Rana

I want to import sklearn but there is no module apparently:

我想导入 sklearn 但显然没有模块:

ModuleNotFoundError: No module named 'sklearn'

I am using Anaconda and Python 3.6.1; I have checked everywhere but still can't find answers.

我正在使用 Anaconda 和Python 3.6.1; 我到处检查,但仍然找不到答案。

When I use the command: conda install scikit-learnshould this not just work?
Where does anaconda install the package?

当我使用命令时: conda install scikit-learn这不应该起作用吗?
anaconda 安装包在哪里?

I was checking the frameworks in my python library and there was nothing about sklearn only numpy and scipy.

我正在检查我的 python 库中的框架,但没有关于 sklearn 的任何内容,只有 numpy 和 scipy。

Please help, I am new to using python packages especially via anaconda.

请帮忙,我是使用 python 包的新手,尤其是通过 anaconda。

回答by mrCarnivore

You can just use pipfor installing packages, even when you are using anaconda:

您可以仅pip用于安装软件包,即使您正在使用anaconda

pip install -U scikit-learn scipy matplotlib

This should work for installing the package.

这应该适用于安装软件包。

And for Python 3.xjust use pip3:

对于Python 3.x,只需使用pip3

pip3 install -U scikit-learn scipy matplotlib

回答by u7109869



Brief Introduction

简单的介绍



When using Anaconda, one needs to be aware of the environment that one is working.

使用 Anaconda 时,需要了解工作环境。

Then, in Anaconda Prompt one needs to use the following code:

然后,在 Anaconda Prompt 中需要使用以下代码:

conda $command -n $ENVIRONMENT_NAME $IDE/package/module

$command- Command that I intend to use (consult documentation for general commands)

$command- 我打算使用的命令有关一般命令,请参阅文档

$ENVIRONMENT NAME- The name of your environment (if one is working in the root, conda $command $IDE/package/moduleis enough)

$ENVIRONMENT NAME- 您的环境名称(如果在 root 中工作, conda $command $IDE/package/module就足够了)

$IDE/package/module- The name of the IDE or package or module

$IDE/package/module- IDE 或包或模块的名称



Solution

解决方案



If one wants to install it in the root and one follows the requirements- (Python (>= 2.7 or >= 3.4), NumPy (>= 1.8.2), SciPy (>= 0.13.3).) - the following will solve the problem:

如果想将其安装在根目录中并遵循要求- (Python (>= 2.7 or >= 3.4), NumPy (>= 1.8.2), SciPy (>= 0.13.3).) - 以下将解决这个问题:

conda install scikit-learn

Let's say that one is working in the environmentwith the name ML.

假设有人在名为ML环境中工作。

Then the following will solve one's problem:

那么以下将解决一个人的问题:

conda install -n ML scikit-learn

Note:If one need to install/update packages, the logic is the same as mentioned in the introduction. If you need more information on Anaconda Packages, check the documentation.

注意:如果需要安装/更新软件包,逻辑与介绍中提到的相同。如果您需要有关Anaconda 软件包的更多信息,请查看文档

回答by yuvraj sune

If you are using Ubuntu 18.04 or higher with python3.xxx then try this command

如果你使用的是 Ubuntu 18.04 或更高版本的 python3.xxx 然后试试这个命令

$ sudo apt install python3-sklearn 

then try your command. hope it will work

然后试试你的命令。希望它会起作用

回答by Claude COULOMBE

I've tried a lot of things but finally, including uninstall with the automated tools. So, I've uninstalled manually scikit-learn.

我已经尝试了很多东西,但最后,包括使用自动化工具卸载。所以,我已经手动卸载了 scikit-learn。

sudo rm -R /home/ubuntu/.local/lib/python3.6/site-packages/sklearn
sudo rm -R /home/ubuntu/.local/lib/python3.6/site-packages/scikit_learn-0.20.0-py3.6.egg-info

And re-install using pip

并使用 pip 重新安装

sudo pip3.6 install -U scikit-learn

Hope that can help someone else!

希望可以帮助别人!

回答by Mohammad ElNesr

This happened to me, I tried all the possible solutions with no luck!

这发生在我身上,我尝试了所有可能的解决方案,但没有运气!

Finaly I realized that the problem was with Jupyter notebook environment, not with sklearn!

最后我意识到问题出在 Jupyter 笔记本环境上,而不是 sklearn 上!

I solved the problem by re-installing Jupyter at the same environment as sklearn

我通过在与 sklearn 相同的环境中重新安装 Jupyter 解决了问题

the command is: conda install -c anaconda ipython. Done...

命令是:conda install -c anaconda ipython。完毕...

回答by mon

Cause

原因

Conda and pip install scikit-learn under ~/anaconda3/envs/$ENV/lib/python3.7/site-packages, however Jupyter notebook looks for the package under ~/anaconda3/lib/python3.7/site-packages.

Conda 和 pip 在 ~/anaconda3/envs/$ENV/lib/python3.7/site-packages 下安装 scikit-learn,但是 Jupyter notebook 在 ~/anaconda3/lib/python3.7/site-packages 下查找包。

Therefore, even when the environment is specified to conda, it does not work.

因此,即使将环境指定为conda,它也不起作用。

conda install -n $ENV scikit-learn # Does not work

Solution

解决方案

pip 3 install the package under ~/anaconda3/lib/python3.7/site-packages.

pip 3 在 ~/anaconda3/lib/python3.7/site-packages 下安装包。

Verify

核实

After pip3, in a Jupyter notebook.

在 pip3 之后,在 Jupyter 笔记本中。

import sklearn
sklearn.__file__

~/anaconda3/lib/python3.7/site-packages/sklearn/init.py'

~/anaconda3/lib/python3.7/site-packages/sklearn/ init.py'

回答by Bharadhydasan

Did you try using the Ananconda navigator for installing the package. If you have created different environments, make sure you launch the correct notebook.

您是否尝试使用 Ananconda 导航器安装软件包。如果您创建了不同的环境,请确保启动正确的笔记本。