I want to import sklearn but there is no module apparently:
ModuleNotFoundError: No module named \'sklearn\'
I am using Anaconda and
This happened to me, I tried all the possible solutions with no luck!
Finaly I realized that the problem was with Jupyter notebook environment, not with sklearn!
I solved the problem by re-installing Jupyter at the same environment as sklearn
the command is: conda install -c anaconda ipython
. Done...
Conda and pip install scikit-learn under ~/anaconda3/envs/$ENV/lib/python3.7/site-packages, however Jupyter notebook looks for the package under ~/anaconda3/lib/python3.7/site-packages.
Therefore, even when the environment is specified to conda, it does not work.
conda install -n $ENV scikit-learn # Does not work
pip 3 install the package under ~/anaconda3/lib/python3.7/site-packages.
After pip3, in a Jupyter notebook.
import sklearn
sklearn.__file__
~/anaconda3/lib/python3.7/site-packages/sklearn/init.py'
I did the following:
import sys
!{sys.executable} -m pip install sklearn
The other name of sklearn in anaconda is scikit-learn. simply open your anaconda navigator, go to the environments, select your environment, for example tensorflow or whatever you want to work with, search for scikit_learn in the list of uninstalled packages, apply it and then you can import sklearn in your jupyter.
Brief Introduction
When using Anaconda, one needs to be aware of the environment that one is working.
Then, in Anaconda Prompt one needs to use the following code:
conda $command -n $ENVIRONMENT_NAME $IDE/package/module
$command - Command that I intend to use (consult documentation for general commands)
$ENVIRONMENT NAME - The name of your environment (if one is working in the root,
conda $command $IDE/package/module
is enough)
$IDE/package/module - The name of the IDE or package or module
Solution
If one wants to install it in the root and one follows the requirements - (Python (>= 2.7 or >= 3.4), NumPy (>= 1.8.2), SciPy (>= 0.13.3).) - the following will solve the problem:
conda install scikit-learn
Let's say that one is working in the environment with the name ML.
Then the following will solve one's problem:
conda install -n ML scikit-learn
Note: If one need to install/update packages, the logic is the same as mentioned in the introduction. If you need more information on Anaconda Packages, check the documentation.
I've tried a lot of things but finally, including uninstall with the automated tools. So, I've uninstalled manually scikit-learn.
sudo rm -R /home/ubuntu/.local/lib/python3.6/site-packages/sklearn
sudo rm -R /home/ubuntu/.local/lib/python3.6/site-packages/scikit_learn-0.20.0-py3.6.egg-info
And re-install using pip
sudo pip3.6 install -U scikit-learn
Hope that can help someone else!