14

When I run:

from sklearn import datasets

I get the error:

ModuleNotFoundError: No module named 'sklearn'

How can I solve this?

Mehdi Charife
  • 722
  • 1
  • 7
  • 22
Imdadul Haque
  • 1,635
  • 5
  • 23
  • 44

5 Answers5

31

You may also try to install: scikit-learn

pip install scikit-learn

or via Conda:

conda install scikit-learn
POlczak
  • 313
  • 3
  • 4
  • 1
    This is the only correct answer going forward, as the pypi `sklearn` package is being deprecated, and will error on install in every instance at the end of 2023. – LiHRaM Jan 17 '23 at 11:02
  • @LiHRaM Is it being deprecated or is it deprecated? – Mehdi Charife Jun 01 '23 at 21:36
  • 2
    @MehdiCharife My bad. It _is_ deprecated according to the `sklearn` package on pypi: https://pypi.org/project/sklearn/. My wording was due to the brownout schedule, where trying to install `sklearn` fails more and more often until it always errors at end of 2023, but it is already deprecated. – LiHRaM Jun 02 '23 at 13:06
1

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.

0

actually, it is not installed correctly.so to install sklearn, type pip install scikit-learn in the terminal and run.then it will be solved.

-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.

  • 3
    From `poetry add sklearn` `poetry show`: `sklearn 0.0.post1 deprecated sklearn package, use scikit-learn instead`. Installing `scikit-learn` resolves the `sklearn` dependency. – louisdeb Jan 28 '23 at 14:44
-1

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.