8

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 PyPi repository.

14
  • 1
    It means that who ever compiled your matplotlib used a newer version of numpy than is installed on your machine. You need to tell us what OS you are on and how you installed each of these things. The 'current' version of packages is slightly contentious, the library maintainers may say one thing, but the packagers may say another. Commented Oct 27, 2013 at 15:01
  • @tcaswell: OS X 10.9; I don't recall how matplotlib or numpy were originally installed (perhaps with ScypySuperpack?) but both have been maintained for some time with pip. Would removing numpy and reinstalling from scratch do the trick? Commented Oct 27, 2013 at 18:44
  • duh, should have figured osx from the paths. So it used to work and it no longer does? You need someone who actually uses mac (not me) to help you with this. From the number of questions that go by, the scientific software stack on mac is very fragile (and it's apple's fault). Good luck! Commented Oct 27, 2013 at 19:21
  • 1
    @tcaswell: I've made sure that's not the case. I believe that Mavericks did do something like that when it installed, but (a) this worked without errors for a while and (b) I've forced updates of everything with pip so that there's only one matplotlib (or any package) on my path in site-packages, where pip maintains it. Commented Oct 27, 2013 at 19:46
  • 2
    @pv: My path is fine, and I've done the reinstall (remove plus fresh install using pip), in that order, several times; but continued to get the same error. The only thing that worked in the end was sudo pip install -U --force-reinstall scipy. Any idea why that worked when nothing else did? Commented Oct 29, 2013 at 19:39

5 Answers 5

6

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

sudo pip install -U --force-reinstall scipy
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

0

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!

1 Comment

Shouldn't that be "numpy.__version__ and numpy.__file__" ?
0
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 :)

Comments

0

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__

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.