93

I am trying to run the following simple code

import scipy
scipy.test()

But I am getting the following error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 586, in runfile
    execfile(filename, namespace)
  File "C:/Users/Mustafa/Documents/My Python Code/SpectralGraphAnalysis/main.py", line 8, in <module>
    import scipy
  File "C:\Python27\lib\site-packages\scipy\__init__.py", line 61, in <module>
    from numpy._distributor_init import NUMPY_MKL  # requires numpy+mkl
ImportError: cannot import name NUMPY_MKL

I am using python 2.7 under windows 10.

I have installed scipy but that does not seem to solve the problem

Any help is appreciated.

Steve
  • 1,178
  • 1
  • 7
  • 18

9 Answers9

222

If you look at the line which is causing the error, you'll see this:

from numpy._distributor_init import NUMPY_MKL  # requires numpy+mkl

This line comment states the dependency as numpy+mkl (numpy with Intel Math Kernel Library). This means that you've installed the numpy by pip, but the scipy was installed by precompiled archive, which expects numpy+mkl.

This problem can be easy solved by installation for numpy+mkl from whl file from here.

VMAtm
  • 27,943
  • 17
  • 79
  • 125
  • 5
    This solution worked for me running Python 2.7.10 on Windows – ScottMcC May 19 '16 at 02:17
  • 2
    @VMAtm Can we have both the installations of numpy(from pip) and numpy+mkl(from precompiled libs) in the same virtualenvs ? – StrawhatLuffy May 20 '16 at 05:31
  • As far as I know, the answer is no. They are ununstalling each other, as it is a numpy at the end, only with some processor instructions (if I understand it well) – VMAtm May 20 '16 at 07:07
  • 2
    Solution worked perfectly on python 2.7 windows 7. Saved me a lot of time thank you a dozen! – sel Dec 14 '16 at 11:11
  • pip install --user worked for me as I was getting permission issue. – Amit Kumar Feb 28 '17 at 12:49
  • NB if anyone else is trying this, you might need to restart your Python shell after reinstalling Numpy if you've previously tried to import it. I got the same error message until I did – UsAndRufus Mar 08 '17 at 20:35
  • the question is: why did it get installed if it is NOT compatible with the rest of the system? – Antonio Sesto Mar 21 '17 at 08:40
  • @AntonioSesto, for Python there is no difference between `MKL` and non-`MKL`, so **you** need to check versions of packages. – VMAtm Mar 21 '17 at 13:32
  • this really helped me on version 3.6 i had to download the wheel file and install – kinsley kajiva Mar 27 '17 at 13:06
14

Reinstall numpy-1.11.0_XXX.whl (for your Python) from www.lfd.uci.edu/~gohlke/pythonlibs. This file has the same name and version if compare with the variant downloaded by me earlier 29.03.2016, but its size and content differ from old variant. After re-installation error disappeared.

Second option - return back to scipy 0.17.0 from 0.17.1

P.S. I use Windows 64-bit version of Python 3.5.1, so can't guarantee that numpy for Python 2.7 is already corrected.

Andrew
  • 720
  • 1
  • 6
  • 9
11

I'm not sure if this is a good solution but it removed the error. I commented out the line:

from numpy._distributor_init import NUMPY_MKL 

and it worked. Not sure if this will cause other features to break though

Lenny
  • 388
  • 3
  • 15
  • 3
    :) The interesting thing is that it really works and there is no such line in the linux version of scipy. – dzmitry Jul 14 '16 at 07:20
7

I had the same problem while installing gensim on windows. Gensim is dependent on scipy and scipy on numpy. Making all three work is real pain. It took me a lot of time to make all there work on same time.

Solution: If you are using windows make sure you install numpy+mkl instead of just numpy. If you have already installed scipy and numpy, uninstall then using "pip uninstall scipy" and "pip uninstall numpy"

Then download numpy-1.13.1+mkl-cp34-cp34m-win32.whl from http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy and install using pip install numpy-1.13.1+mkl-cp34-cp34m-win32.wh Note: in cp34-cp34m 34 represent the version of python you are using, so download the relevant version.

Now download scipy from http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy (appropriate version for your python and system) and install using "pip install scipy‑0.19.1‑cp34‑cp34m‑win32.whl"

Your numpy and Scipy both should work now. These binaries by Christoph Gohlke makes it very easy to install python packages on windows. But make sure you download all the dependent packages from there.

lucid_dreamer
  • 362
  • 4
  • 9
user3046442
  • 468
  • 5
  • 12
3

I don't have enough reputation to comment but I want to add, that the cp number of the .whl file stands for your python version.

cp35 -> Python 3.5.x

cp36 -> Python 3.6.x

cp37 -> Python 3.7.x

I think it's pretty obvious but still I wasted almost an hour because of this and maybe other people struggle with that, too.

So for me worked version cp36 that I downloaded here: https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy since I am using Python 3.6.8.

Then I uninstalled numpy:

pip uninstall numpy 

Then I installed numpy+mkl:

pip install <destination of your .whl file>
Adrian
  • 363
  • 3
  • 12
2

The reason for the error is you upgraded your numpy library of which there are some functionalities from scipy that are required by the current version for it to run which may not be found in scipy. Just upgrade your scipy library using python -m pip install scipy --upgrade. I was facing the same error and this solution worked on my python 3.5.

0

From your log its clear that numpy package is missing. As mention in the PyPI package:

The SciPy library depends on NumPy, which provides convenient and fast N-dimensional array manipulation.

So, try installing numpy package for python as you did with scipy.

JRodDynamite
  • 12,325
  • 5
  • 43
  • 63
manoj prashant k
  • 339
  • 1
  • 13
  • 3
    I also had that installed. For some reason I had to close Spyder and run it again and that solved the problem. Thanks anyway. – Steve May 17 '16 at 05:05
  • 2
    This error arises even if numpy is present, if numpy has not been compiled with MKL support. – KDN Jan 12 '17 at 19:38
  • Worked. thanks my scikit was from http://www.lfd.uci.edu/~gohlke/pythonlibs/ So had to use the numpy from the same distro – Anuvrat Tiku Jul 09 '17 at 14:15
0

I recently got the same error when trying to load scipy in jupyter (python3.x, win10), although just having upgraded to numpy-1.13.3+mkl through pip. The solution was to simply upgrade the scipy package (from v0.19 to v1.0.0).

E. V.
  • 43
  • 1
  • 7
0

yes,Just reinstall numpy,it works.