Raj
Raj

Reputation: 2028

Import Error on importing sklearn in Python

I am new to python and installed it in windows OS and while following Google's machine learning tutorial on youtube, i encountered an error while importing the scikit package.

I installed the Anaconda package as shown in the tutorial but when importing sklearn i get an import error.

import sklearn

i also tried

from sklearn import tree

This is the error

Traceback (most recent call last):
  File "C:\Users\Raj Asha\Desktop\hello-world.py", line 2, in <module>
    from sklearn import tree
ModuleNotFoundError: No module named 'sklearn'

python version is 3.6.1

link to tutorial video https://www.youtube.com/watch?v=cKxRvEZd3Mw

Upvotes: 3

Views: 30971

Answers (3)

Enrique
Enrique

Reputation: 134

I tried multiple solutions, but none of them worked. I installed the wheel files:

scipy-1.8.0-cp310-cp310-win_amd64.whl
numpy-1.22.3+mkl-cp310-cp310-win_amd64.whl
scikit_learn-1.0.2-cp310-cp310-win_amd64.whl

But I got error in: import sklearn

In my case, I was able to solve this by installing the whl file of the joblib (before, do: pip install wheel).

Download: https://github.com/wikimedia/research-ores-wheels/blob/master/joblib-0.14.1-py2.py3-none-any.whl

pip uninstall joblib
pip install .../joblib-0.14.1-py2.py3-none-any.whl

Upvotes: 1

vhd
vhd

Reputation: 17

update your anaconda and python. I had the same problem. had to change my windows from 7 to 10 because python 3.9 doesn't support windows 7 or earlier anymore

Upvotes: 0

seralouk
seralouk

Reputation: 33147

Do you use Windows? From the error that you posted I say yes.

Open your terminal (cmd) and try these before you try to import the sklearn.

pip install -U scikit-learn

or

conda install scikit-learn

Also make sure your have numpy and scipy:

pip install numpy 
pip install scipy

EDIT

The conda error means that the conda is not in you PATH environment.

To solve this, Uninstall Anaconda and install it again, this time by selecting BOTH the options in the installation instruction as shown:

enter image description here

EDIT 2

If you do not have pip then, download from here the get-pip.py file and then use cmd to run python get-pip.py inside the folder in which get-pip.py is saved

Upvotes: 6

Related Questions