When I run:
from sklearn import datasets
I get the error:
ModuleNotFoundError: No module named 'sklearn'
How can I solve this?
When I run:
from sklearn import datasets
I get the error:
ModuleNotFoundError: No module named 'sklearn'
How can I solve this?
You may also try to install: scikit-learn
pip install scikit-learn
or via Conda:
conda install scikit-learn
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.
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.
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.
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.