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
sixmoduleNext, you will install the six module separately using the following command:
pip install six
- Step 3: Use the
sixmodule from a different locationNext, 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:
import sys
sys.path.append(‘/path/to/six’) - Step 4: Use the
compatmodule from scikit-learnThen, 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
joblibinstead ofsklearn.externals.sixFor 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
Frequently Asked Questions
What is Python ModuleNotFoundError and what causes it?
ModuleNotFoundError (a subclass of ImportError) is raised when Python cannot find the module you tried to import. Common causes: the package isn’t installed (pip install missing), wrong virtual environment activated, typo in module name, or Python can’t find your local module on the import path. The error message names exactly which module is missing.
How do I fix ‘ModuleNotFoundError: No module named X’?
Run pip install X first. If that succeeds but you still get the error, check which Python you’re using (which python OR python –version) vs which pip (which pip OR pip –version), they must match. Common gotcha: pip points to system Python 3.9 but you’re running python3.11 in a venv. Inside the venv, use python -m pip install X to be sure pip matches the active Python.
Why does my code work in one environment but not another?
Different Python versions or different installed packages. To diagnose: pip freeze > requirements.txt on the working environment, then pip install -r requirements.txt on the broken one. Use virtualenv (python -m venv venv) or conda for every project to avoid system-wide package collisions.
Is ModuleNotFoundError the same as ImportError?
ModuleNotFoundError is a subclass of ImportError added in Python 3.6. It specifically means ‘no such module exists.’ Plain ImportError covers a wider set: module exists but a name inside it can’t be imported (e.g. ‘cannot import name X from Y’). except ImportError catches both; except ModuleNotFoundError catches only the missing-module case.
Where can I find more ModuleNotFoundError fixes?
Browse the ModuleNotFoundError reference hub for 198+ specific module fixes (TensorFlow, Flask, Django, pandas, numpy, etc.). For related issues see ImportError. For broader Python setup see Python Tutorial hub.
Conclusion
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.



