In this post, we will learn the solutions on how to solve the no module named ‘sklearn.externals.six’
What is sklearn.externals.six?
The sklearn.externals.six module in the scikit-learn library provides compatibility between Python 2 and Python 3.
It consists of efficiency functions and classes that allow code written for Python 2 to run smoothly on Python 3.
However, you must take note that sklearn.externals.six is now considered a history module.
Because it has been removed in the latest version of scikit-learn (1.0).
Also, you might interested to read or visit the other resolved error:
- modulenotfounderror: no module named keras.objectives [Solved]
- Modulenotfounderror: no module named ‘wget’ [SOLVED]
Why error the no module named sklearn.externals.six occur?
The error “ModuleNotFoundError: No module named ‘sklearn.externals.six’” is occur if you’re trying to import the six module from the sklearn.externals module. It is does not exist in your Python environment.
In addition, this issue will occur if you are using an outdated version of scikit-learn. When you have installed scikit-learn it is interrupted during the installation.
For newer versions of scikit-learn, the six module has been moved to a separate package, six, which can be installed separately.
How to solve the no module named ‘sklearn.externals.six’?
Time needed: 3 minutes.
Here are some steps to resolve the “modulenotfounderror: no module named ‘sklearn.externals.six’” error:
- Step 1: Upgrade scikit-learn
First, You can try to upgrade Scikit-Learn to the latest version using the following command:
pip install –upgrade scikit-learn
If you run the following command it upgrade the scikit-learn packages to the latest version in your python environment:
- Step 2: Install
Next, you will install the six module separately using the following command:
pip install six
- Step 3: Use the
sixmodule from a different location
Next, When you have multiple Python environments or virtual environments, you can try to import the six module from a different location using the following code before importing scikit-learn:
- Step 4: Use the
compatmodule from scikit-learn
Then, For newer versions of scikit-learn, the six module has been moved to the sklearn.utils package. You can import the compat module from sklearn.utils to access the six module. Here is the following code:
from sklearn.utils import compat
If none of these steps work, you can proceed to the next step
- Step 5: Downgrade scikit-learn
After that, if you cannot upgrade the scikit-learn package or cannot use the latest version for some reason, you can try to downgrade scikit-learn to an earlier version that is compatible with the sklearn.externals.six module. You can install an earlier version of scikit-learn using the following command:
pip install scikit-learn==1.1
If you run the following command above it will downgrade the specific scikit-learn packages to your python environment:
- Step 6: Use
For newer versions of scikit-learn, the joblib module will be able to be used instead of sklearn.externals.six. You can import the joblib package and use it instead of sklearn.externals.six. The following code to import:
from joblib import Parallel, delayed
In conclusion, the “ModuleNotFoundError: No module named ‘sklearn.externals.six’” error will be resolved through upgrading or downgrading scikit-learn.
Through installing the six module separately, importing the compat module from scikit-learn, using joblib instead of sklearn.externals.six, or reinstalling your entire Python environment.