Python 让 PyC​​harm 导入 sklearn

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

Getting PyCharm to import sklearn

pythonscikit-learnpython-importanaconda

提问by BabbaBooey

Beginner here.

初学者在这里。

I'm trying to use sklearnin pycharm. When importing sklearnI get an error that reads “Import error: No module named sklearn” The project interpreter in pycharmis set to 2.7.10 (/anaconda/bin/python.app), which should be the right one. Under default preferenes, project interpreter, I see all of anacondaspackages. I've double clicked and installed the packages scikit learnand sklearn. I still receive the “Import error: No module named sklearn”

我正在尝试sklearnpycharm. 导入时,sklearn我收到一条错误消息,内容为“导入错误:未命名模块sklearn”中的项目解释器pycharm设置为 2.7.10 (/anaconda/bin/python.app),这应该是正确的。在默认首选项、项目解释器下,我看到了所有的anacondas包。我已经双击并安装了软件包scikit learnsklearn. 我仍然收到“导入错误:没有名为 sklearn 的模块”

Does anyone know how to solve this problem?

有谁知道如何解决这个问题?

回答by Sithara

Double check your python interpreter. Check whether you have select correct interpreter at the first when you create the project.

仔细检查你的 python 解释器。创建项目时首先检查您是否选择了正确的解释器。

Refer this-Image of checking interpreter when Create project

参考这个-创建项目时检查解释器的图像

Or else you can check your interpreter from the project view under External Libraries.

或者,您可以从外部库下的项目视图中检查您的解释器。

Refer this-Image of checking interpreter from Project view

参考这个-从项目视图检查解释器的图像

In your case if you didn't select 2.7.10 (/anaconda/bin/python.app) as your interpreter for the project at the beginning still the program give the same error Import error: No module named sklearn.

在您的情况下,如果您在开始时没有选择 2.7.10 ( /anaconda/bin/python.app) 作为项目的解释器,程序仍然会给出相同的错误Import error: No module named sklearn

回答by SPanchakarla

To make sure you have Scikit-learn package installed on your PyCharm IDE, go to File Menu>Settings and search for Interpreter. Select Project Interpreter, and if you dont see Scikit-learn in the list of packages, click the + sign on the right end. It brings us another window with a search bar, where you can type 'Scikit-learn' and install (see screenshots). I hope this helps.

要确保在 PyCharm IDE 上安装了 Scikit-learn 包,请转到文件菜单>设置并搜索解释器。选择 Project Interpreter,如果在包列表中没有看到 Scikit-learn,请单击右端的 + 号。它为我们带来了另一个带有搜索栏的窗口,您可以在其中键入“Scikit-learn”并安装(请参见屏幕截图)。我希望这有帮助。

Screenshots:Interpreter Settings, Install Package

截图:口译设置安装包

回答by Akhzar Nazir

Same error occurs to me i have fixed by selecting File Menu-> Default Settings-> Project Interpreter -> Press + button and type 'sklearn' Press install button. Installation will be done in 10 to 20 seconds.

同样的错误发生在我身上,我通过选择文件菜单->默认设置->项目解释器->按+按钮并输入'sklearn'按安装按钮来修复。安装将在 10 到 20 秒内完成。

If issue not resolved please check you PyCharm Interpreter path. Sometimes your machine have Python 2.7 and Python 3.6 both installed and there may be some conflict by choosing one.

如果问题未解决,请检查您的 PyCharm 解释器路径。有时您的机器同时安装了 Python 2.7 和 Python 3.6,选择其中一个可能会发生冲突。

回答by Joydeep

For Mac OS:

对于 Mac 操作系统:

PyCharm --> Preferences --> Project Interpreter --> Double Click on pip (a new window will open with search option) --> mention 'Scikit-learn' on the search bar --> Install Packages --> Once installed, close that new window --> OK on the existing window

PyCharm --> 首选项 --> 项目解释器 --> 双击 pip(将打开一个带有搜索选项的新窗口) --> 在搜索栏上提及“Scikit-learn” --> 安装包 --> 一旦安装, 关闭那个新窗口 --> 在现有窗口上确定

and you are done.

你就完成了。

回答by Wen Qi

please notice that, in the packages search 'Scikit-learn', instead 'sklearn'

请注意,在包中搜索“ Scikit-learn”,而不是“ sklearn

回答by MarkBC

I had exactly the same problem. I'm using PyCharm with Anaconda3 & Python 3.7, and I've installed other packages into/via PyCharms just fine (such as numpy, scipy, and others). But although scikit-learn (which contains sklearn, that was initially confusing) seems fully installed on my system, including "import sklearn" working outside of PyCharm, I could not get the "import sklearn" to succeed inside PyCharm.

我遇到了完全相同的问题。我正在将 PyCharm 与 A​​naconda3 和 Python 3.7 一起使用,并且我已经将其他软件包安装到/通过 PyCharms 就好了(例如 numpy、scipy 等)。但是,尽管 scikit-learn(包含 sklearn,最初令人困惑)似乎完全安装在我的系统上,包括在 PyCharm 之外工作的“import sklearn”,但我无法让“import sklearn”在 PyCharm 内成功。

I finally got a python-expert friend to help me. He verified everything was correctly installed on my system and verified that PyCharm was somehow messing up.

我终于得到了一个 Python 专家朋友的帮助。他确认一切都正确安装在我的系统上,并确认 PyCharm 以某种方式搞砸了。

We finally determined that the venv (virtual environment) was not including scikit-learn (sklearn) even though I had imported it properly into the Project Interpreter in PyCharms.

我们最终确定 venv(虚拟环境)不包括 scikit-learn (sklearn),即使我已将其正确导入 PyCharms 中的 Project Interpreter。

Solution:Delete and recreate the VENV, specifically ticking the box Inherit Global Site Packages

解决方法:删除并重新创建VENV,特别是勾选Inherit Global Site Packages

See here: https://www.jetbrains.com/help/pycharm/creating-virtual-environment.htmlfor how to create a new virtual environment and get to that parameter.

请参阅此处:https: //www.jetbrains.com/help/pycharm/creating-virtual-environment.html了解如何创建新的虚拟环境并获取该参数。

回答by Meherameem

go to terminal- type python -m pip install scikit-learnthen hit enter. give it some seconds. It will be done. Sample Image

转到终端类型,python -m pip install scikit-learn然后按回车键。给它几秒钟。将会完成。 示例图像