. Advertisement .
..3..
. Advertisement .
..4..
Python is a well-known and widely-used programming language in the world. While working with python, we use a virtual environment to maintain our projects or applications. However, there are many times you might run into an error “ModuleNotFoundError: No module named ‘sklearn’”. In order to make it clear as well as how to resolve this error, let’s continue to stay tuned for our post to be able to find out the way!
How Did This Error Occur?
If you have experience with Python, you must know the word ‘sklearn’ (Scikit-Learn). It is a standard Machine Learning library in the Python programming language. When you try to import this library, you can be faced with this message ModuleNotFoundError: No module named ‘sklearn’.
Cause of error
It may be caused by Python not locating the module in the import command or your Jupyter notebook may be importing sklearn or other libraries from the location(path) in contrast to the libraries that are pip or conda.
How To Solve ModuleNotFoundError: No module named ‘sklearn’ Error ?
The system cannot find out the sklearn during the execution of the code. Here are the ways you can install sklearn on your system.
1. For Ubuntu operating system
For versions of ubuntu 18.04 or higher and python3.xxx, you can use the following command to install sklearn:
$ sudo apt install python3-sklearn
2. Using pip
Another method is you can install the package with pip, it is applicable to anaconda.
In Python 3, you should use this line command
pip3 install -U scikit-learn scipy matplotlib
If your Python version is lower, try with this command:
pip install -U scikit-learn scipy matplotlib
3. Install sklearn with conda
This error might be solved when you install sklearn and use the conda . Typing this
conda install scikit-learn
Or the other one is
conda install -n ML scikit-learn
4. Reinstall
Make sure that the sklearn library exists. The thing you need to do is delete this directory and completely uninstall sklearn. In this way, import the following command to manually uninstall scikit-learning:
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
Now, reinstall the sklearn on your system by the following command
sudo pip3 install -U scikit-learn
Don’t worry about the ‘scikt-learn’, it is the full name of sklearn.
Conclusion
Four solutions are pointed out in our post. We hope the error ModuleNotFoundError: No module named ‘sklearn’ no longer makes it difficult for you.
Have you chosen any solution yet, please leave a comment to let us know your results? We really appreciate your comments.
Leave a comment