ImportError: cannot import name 'joblib' from 'sklearn.externals'
Third-person routing text. Fixes ImportError for joblib from sklearn.externals: scikit-learn 0.23 removed the vendored copy. Import joblib directly (pip install joblib). Use when an agent hits this on old code with new sklearn. Not for other sklearn.externals removals.
TL;DR: scikit-learn 0.23 removed its vendored joblib. Change from sklearn.externals import joblib to plain import joblib (install it if missing).
The error
ImportError: cannot import name 'joblib' from 'sklearn.externals'Fix it
- Replace the import:
import joblibExpected: no import error.
- If joblib is not installed:
pip install joblib- Verify:
python -c "import joblib; print(joblib.__version__)"Expected: prints a version.
When this applies
Use this when old code or tutorials do from sklearn.externals import joblib on scikit-learn 0.23+.
When it does not apply
If the error names a different sklearn.externals member (like six), that vendored copy is gone too; find its standalone package. If sklearn itself will not import, reinstall it.
Compatibility
scikit-learn 0.23+. Plain import joblib works on every sklearn version.
Root cause
sklearn used to vendor joblib under sklearn.externals. In 0.23 the vendored copy was dropped and joblib became a proper declared dependency, so the old import path no longer exists.
Edge cases
Old pickles saved with sklearn.externals.joblib still load fine with standalone joblib. If a requirements file pins ancient sklearn, upgrading sklearn is better than working around the import.