Solving ImportError: cannot import name NUMPY_MKL in Python

ImportError: cannot import name NUMPY_MKL in Python is a Python error which occurs when you do not have numpy and mkl or when you have a faulty numpy and mkl installation.

In this article I am going to solve the error while I try explaining why the error is popping up in the first place, I will also introduce some solutions which worked for other developers and we will see if those solutions can solve the error in your unique situation.

Exploring the ImportError: cannot import name NUMPY_MKL in Python

First of all, we should know that this error occurs when you do not have numpy and mkl or when you have a faulty numpy and mkl installation.

If your error looks like the error bellow then great. Please make sure you are not confusing this error with other errors.

                                                                       #
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    execfile(filename, namespace)
  File "C:/Users/Mustafa/Documents/My Python Code/SpectralGraphAnalysis/main.py", line 8, in <module>
    import scipy
ImportError: cannot import name NUMPY_MKL
                                                                       #

The error can happen because of one simple import of scipy just like in the code bellow.

                                                                       #
import scipy
scipy.test()
                                                                       #

Bellow we will describe how the error can be solved. With multiple possible solutions.

Solution 1 : install numpy + mkl.

First, we need to understand the problem. Scipy expects you to have numpy+mkl (mkl stands for Intel Math Kernel Library).

If you have used pip to install numpy then you will face this error.

The first solution is to install the correct cp for python plus an extra number of steps. You need to realize that the cp number of .whl stands for the version of python you have.

                                                                       #
https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
                                                                       #

Use the link above to the download the version that suits you.

Now that we are done with the first step, you should uninstall numpy by using pip uninstall.

                                                                       #
pip uninstall numpy 
                                                                       #

Finally, you should install numpy and mkl.

                                                                       #
pip install <path> # path is the destination of your .whl filev
                                                                       #

This solution should be enough but if the first solution does not solve the problem you should try the second solution.

Solution 2 : Comment the NUMPY_MKL import.

Another solution, is to avoid installing numpy with mkl and instead commenting the NUMPY_MKL import in your code. This should work for most instances of this error.

The import you should comment is the line bellow.

                                                                       #
from numpy._distributor_init import NUMPY_MKL 
                                                                       #

This should be enough to get rid of the error for good. If you start having other errors then its better to look for other solutions or use the first solution.

I hope the solutions have been helpful, I hope you soulved the error already, you can support us by donating to our Kofi account, this website is free to use but any help is very appreciated and goes a long way.

Summing-up

I can not find any other solution to the problem guys, I tried my best, I hope the above solutions worked for you, cheers, keep coding. If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/