Pergunta

When I

import matplotlib

I get no errors, but when I

import matplotlib.pyplot

I get

RuntimeError: module compiled against API version 8 but this version of numpy is 7
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/matplotlib/pyplot.py", line 24, in <module>
    import matplotlib.colorbar
  File "/Library/Python/2.7/site-packages/matplotlib/colorbar.py", line 27, in <module>
    import matplotlib.artist as martist
  File "/Library/Python/2.7/site-packages/matplotlib/artist.py", line 8, in <module>
    from transforms import Bbox, IdentityTransform, TransformedBbox, \
  File "/Library/Python/2.7/site-packages/matplotlib/transforms.py", line 35, in <module>
    from matplotlib._path import (affine_transform, count_bboxes_overlapping_bbox,
ImportError: numpy.core.multiarray failed to import

This looks like a version error; but yolk says I have an up-to-date version, and pip says everything is up-to-date and won't help "really" update things.

What can I do to make sure that the necessary packages are "really" up-to-date to avoid this error; what packages need to be "really" updated (matplotlib; numpy; others?).


Uninstalling and re-istalling numpy (using pip) does not help.

Did pip somehow let me recently update matplotlib to "too new" a version, wile the pip version of numpy lags?


My sys.path is:

['',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',  
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',  
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',  
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',  
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',  
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',  
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',  
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',  
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', 
'/Library/Python/2.7/site-packages']

and the Scypi stack is installed in site-packages where it is maintained by pip. OS X 10.9, Apple Python 2.7.5, all packages versions are those found by pip in PiPy.

Foi útil?

Solução

Forcing reinstall works in this case, as it will often do in similar cases:

sudo pip install -U --force-reinstall scipy

Outras dicas

I had this same error as well. I was able fix it by installing numpy through my python IDE. I am using PyCharm. When Pycharm opens there is an option to configure things and from there you can select python interpreters. On the righthand side a panel should appear with two options; paths and packages. select packages, then select install, and a list of available packages will pop up. Select numpy from the list and click install from this window. this fixed my error.

In case

sudo pip install -U --force-reinstall scipy

doesn't work (even if you include a specific version), you may want to make sure you've got the right version of numpy installed with the Python you're using. I had the same "numpy.core.multiarray failed to import" issue, but it was because I had 1.6 installed for the version of Python I was using, even though I kept installing 1.8 and assumed it was installing in the right directory.

I found the bad numpy version by using the following command in my Mac terminal:

python -c "import numpy;print numpy.version;print numpy.file";

This command gave me the version and location of numpy that I was using (turned out it was 1.6.2). I went to this location and manually replaced it with the numpy folder for 1.8 (the pip command had installed this elsewhere), which resolved my "numpy.core.multiarray failed to import" issue. Hopefully someone finds this useful!

sudo pip install -U --force-reinstall scipy

works for me, but when you restart on a mac, you have to uncheck the "reopen windows" to make that work

not just restarting :)

I had the same problem and the cause seems to be the older versions of numpy (as well as scipy,matplotlib in other cases) shipped with Mac OS X mavericks. The following link contains the solution.

https://stackoverflow.com/a/28518106

One need manually delete the older modules located in (in my case) /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/

Then upgrade the modules. The new modules are located in /Library/Python/2.7/site-packages/

One can make sure the import is done by checking

import numpy

print numpy.__file__ or

print numpy.__version__

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top