Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named sklearn (Python)

Tags:

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

like image 860
Lorenzo Vannucchi Avatar asked Apr 04 '16 13:04

Lorenzo Vannucchi


People also ask

How do I fix No module named Sklearn?

The Python "ModuleNotFoundError: No module named 'sklearn'" occurs when we forget to install the scikit-learn module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install scikit-learn command.


2 Answers

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

like image 77
Igor Fil Avatar answered Sep 19 '22 21:09

Igor Fil


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')
like image 44
abdellah el atouani Avatar answered Sep 19 '22 21:09

abdellah el atouani