27

I’m trying to use sklearn in Pycharm. When I import sklearn I get the error:

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 preferences, project interpreter, I see all of Ancaconda's packages. I've double clicked and installed the packages scikit learn and sklearn, but I still receive the same error message.

How can I solve this?

Mehdi Charife
  • 722
  • 1
  • 7
  • 22
BabbaBooey
  • 381
  • 1
  • 4
  • 4
  • 1
    The 3rd paragraph in the answer in this link is the closest to solving the problem. Although I'm not "prompted to install setup_tools and pip for that interpreter" (http://stackoverflow.com/questions/18931049/getting-pycharm-to-recognize-anacondas-scipy). – BabbaBooey Sep 20 '15 at 02:12
  • You need to use the correct interpreter. In pycharm select the right interpreter. – tumbleweed Sep 22 '15 at 04:51

8 Answers8

59

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

Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146
SPanchakarla
  • 591
  • 4
  • 3
10

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

Wen Qi
  • 655
  • 7
  • 9
5

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

Axiumin_
  • 2,107
  • 2
  • 15
  • 24
Meherameem
  • 51
  • 1
  • 2
3

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

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.

Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146
Sithara
  • 339
  • 3
  • 4
2

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.

MarkBC
  • 95
  • 8
1

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.

Akhzar Nazir
  • 724
  • 9
  • 13
1

SOLVED:

  1. reinstalled Python 3.7.9 (not the latet)
  2. installed numpy 1.17.5 (not the latest)
  3. installed scikit-learn (latest)

sklearn works now!

Andrei
  • 11
  • 1
0

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.

Joydeep
  • 11
  • 1