Imdadul Haque
Imdadul Haque

Reputation: 1855

ModuleNotFoundError: No module named sklearn

When I run:

from sklearn import datasets

I get the error:

ModuleNotFoundError: No module named 'sklearn'

How can I solve this?

Upvotes: 15

Views: 33652

Answers (4)

Peter Rowlett
Peter Rowlett

Reputation: 111

This confused me after reading several posts about this.

To make sure I was installing to the right Python, I did this:

python -m pip install sklearn

It said

Requirement already satisfied: sklearn in /home/.../lib/python3.10/site-packages (0.0.post5)

Then I typed python to get the prompt and then import sklearn. It said ModuleNotFoundError: No module named 'sklearn'. But I just installed it, right? Wrong!

I ran python -m pip show sklearn and it said

Name: sklearn
Version: 0.0.post5
Summary: deprecated sklearn package, use scikit-learn instead

This is saying sklearn isn't the package to install to get the module sklearn. Instead I should install scikit-learn to get the module sklearn.

So I ran python -m pip uninstall sklearn and then python -m pip install scikit-learn. Now when I open python and type import sklearn it imports scikit-learn.

I feel this is unnecessarily confusing (that sklearn isn't installed as sklearn) so I'm posting here in hopes that it helps someone else.

Upvotes: 1

POlczak
POlczak

Reputation: 333

You may also try to install: scikit-learn

pip install scikit-learn

or via Conda:

conda install scikit-learn

Upvotes: 33

Mohammed Masood Ahmed
Mohammed Masood Ahmed

Reputation: 27

If PIP is already installed on you PC, its just a matter of running a single command pip install sklearn and it will install the sklearn module easily. You can refer to https://scikit-learn.org/stable/install.html.

else you will need to install pip. Refer https://phoenixnap.com/kb/install-pip-windows for PIP installation.

Upvotes: -1

you basically not installed sklearn library.. so first install sklearn with below command.

pip install sklearn

and then run the code it will resolve your issue.

Upvotes: -1

Related Questions