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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With