Sklearn is a free and open-source library for building machine learning models. It has many algorithms like classification, regression, and clustering that makes the task very easy to build a predictive model. But sometimes you can face errors like modulenotfounderror: no module named sklearn which may be a tedious task to solve. In this tutorial, you will know how to solve the error like modulenotfounderror: no module named sklearn easily.
What is ModuleNotFoundError?
ModuleNotFound is an error you will get when the python package is not installed in your system. For example, suppose you are importing package X without installing it in your system you will get the modulenotfounderror: no module named X error. The python interpreter is telling you that you have to install package X before using it in your system.
The Root Cause of the modulenotfounderror: no module named sklearn
The main cause for the no module named sklearn error is that you have not installed the scikit-learn package in your system. You will get the underline below the sklearn word in Pycharm when you try to import the sklearn module. It is clearly stating that the sklearn is not installed in your system.
Execute the below code you will get the error.
import sklearn
Output
Traceback (most recent call last):
File "your_project_path", line 1, in
import sklearn
ModuleNotFoundError: No module named 'sklearn'
The same error you will get in the terminal or command prompt if you will import the sklearn module.

Solution for the modulenotfounderror: no module named sklearn
The solution for this no module named sklearn is very simple. The sklearn module comes with scikit-learn. Therefore you have to install it in your system. But before that, you have to find the version of the python installed in your system.
Use the below command to check the version of the python.
python --version
Output

If your system has a python 3. xx version use the pip3 command and if the version is 2. xx then use the pip command.
My system has a 3. xx version so I will use the pip3 command.
Open your terminal or command prompt and type the following command to install scikit-learn in your system.
pip3 install scikit-learn
Output
Now if you import the sklearn you will not get any error on Pycharm or command prompt.

Conclusion
Sklearn is a very useful module for implementing machine learning applications. The above method will solve the error if you are getting modulenotfounderror: no module named sklearn error.
Leave a Reply