Getting PyCharm to import sklearn

2020-07-02 08:36发布

Beginner here.

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

Does anyone know how to solve this problem?

7条回答
家丑人穷心不美
2楼-- · 2020-07-02 08:40

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

查看更多
Luminary・发光体
3楼-- · 2020-07-02 08:42

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.

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.

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.

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

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

查看更多
▲ chillily
4楼-- · 2020-07-02 08:45

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.

Screenshots: Interpreter Settings, Install Package

查看更多
别忘想泡老子
5楼-- · 2020-07-02 09:03

For Mac OS:

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

and you are done.

查看更多
放我归山
6楼-- · 2020-07-02 09:04

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.

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.

查看更多
三岁会撩人
7楼-- · 2020-07-02 09:05

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

查看更多
登录 后发表回答