Lorenzo Vannucchi
Lorenzo Vannucchi

Reputation: 399

ImportError: No module named sklearn (Python)

I wanna use scikit-learn. I have typed

pip install -U scikit-learn
pip3 install sklearn

to install it; but when i type

$ Python
>>> import sklearn

it returns

ImportError: No module named sklearn

I followed other tutorials, but it doesn't work. Furthermore, my enviroment returns this warning:

If you have installed scikit-learn from source, please do not forget to build the package before using it: run python setup.py install or make in the source directory.

What is the true code to type in the terminal? I tried to type python setup.py installin the terminal but it doesn't work

Upvotes: 28

Views: 129468

Answers (8)

Batuhan Yamaner
Batuhan Yamaner

Reputation: 26

sklearn is deprecated, use scikit-learn.

Here is how to fix this error in the main use cases:

  • Use 'pip install scikit-learn' rather than 'pip install sklearn'
  • Replace 'sklearn' with 'scikit-learn' in your pip requirements files (requirements.txt, setup.py, setup.cfg, pipfile, etc ...)

Upvotes: 0

Had the same issue, solved with the following steps:

check python version with command:

$ python --version

if version is python 2.7, use:

$ sudo pip2 install <package_name>

of if the python version 3 is installed, use pip3 instead of pip2

Upvotes: 0

Rahul Sood
Rahul Sood

Reputation: 109

this may happen that you have multiple versions of python and pip, do the following:

check your python version by typing:

    python --version 

for python 3.8, install sklearn using

    pip3.8 install sklearn

for python 3.7, install sklearn using

    pip3.7 install sklearn

for python 3.6, install sklearn using

    pip3.6 install sklearn

and so on ....

Upvotes: 0

Haider Rizvi
Haider Rizvi

Reputation: 61

Try:

pip3 install scikit-learn

Upvotes: 6

user3409586
user3409586

Reputation: 11

Not only for this package but also for almost cases, please try using python3 -m pip install sklearn if pip install sklearn does not work.

Upvotes: 1

abdellah el atouani
abdellah el atouani

Reputation: 171

you dont have the package scikit-learn installed, try this if you are in a terminal linux :

sudo pip install scikit-learn

if you want to install the package within your code use

import os 
os.system('sudo pip install scikit-learn')

Upvotes: 12

Sean
Sean

Reputation: 720

I think you havent install sklearn, try this on your python terminal:

pip install sklearn

and proceed with your code

Upvotes: 0

Igor Fil
Igor Fil

Reputation: 212

Make sure that pip and python are the same version. For example if you run pip for python 2.7, it will install the package only in 2.7, and if your python command point to for example python 3.3 interpreter, it will not have that package

Upvotes: 18

Related Questions