Importerror: cannot import name joblib from sklearn.externals ( Solved )

Importerror cannot import name joblib from sklearn externals

Importerror: cannot import name joblib from sklearn.externals  error occurs due to deprecation of sklearn.externals.joblib in version 0.21. In a few later versions ( Till 0.23)  this syntax structure works with a warning but after the same, The developer community of scikit-learn completely removed it. Hence if you are using any version later than 0.23 ( sklearn ), You will get this error. Now let’s talk about the solution for this. All we need to direct import joblib in the place for sklearn.externals.joblib then the interpreter will not throw any error.

Well, we are going to understand all theoretical explanations in a more practical way in the below section.

Importerror: cannot import name joblib from sklearn.externals ( Direct Solution ) –

Solution 1: Changing imports –

Typically when we write this syntax we get the error –

from sklearn.externals import joblib

Correct Version –

import joblib

All we need to simply change the import statements then we can get rid of the error.

Importerror cannot import name joblib from sklearn.externals
Importerror cannot import name joblib from sklearn.externals

One more important thing to mention. Please make sure if joblib is not installed in your system, You can install it via the pip package manager. You may use the below command for this-

pip install joblib

This will install the latest version for joblib in your system.

Solution 2: Downgrading sklearn version –

Since, Till now you have already understood that the above syntax is compatible with sklearn 0.21 or below version. Then one solution is to downgrade this skelarn to those versions. But the major drawback of this approach is that you will lose multiple valuable features of the latest version. Hence we will not recommend using this way.

Now let’s understand the other aspect of the error-

1. Most common scenario for this error?

Typically while loading and dumping scikit-learn model, we use this package.  There if we are using any incompatible scikit learn module, we get this error.

2. What is the core purpose of joblib module?

This is a lightweight python pipeline development framework.

 

Thanks

Data Science Learner Team

Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for signup. A Confirmation Email has been sent to your Email Address.

Something went wrong.

Meet Abhishek ( Chief Editor) , a data scientist with major expertise in NLP and Text Analytics. He has worked on various projects involving text data and have been able to achieve great results. He is currently manages Datasciencelearner.com, where he and his team share knowledge and help others learn more about data science.
 
Thank you For sharing.We appreciate your support. Don't Forget to LIKE and FOLLOW our SITE to keep UPDATED with Data Science Learner