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.

JIST
  • 1,139
  • 2
  • 8
  • 30
orome
  • 45,163
  • 57
  • 202
  • 418
  • 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. – tacaswell Oct 27 '13 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? – orome Oct 27 '13 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! – tacaswell Oct 27 '13 at 19:21
  • @tcaswell: I guess not (tried and got the same error). I'm confused how this could have happened: I'm the one compiling (using pip), right? – orome Oct 27 '13 at 19:34
  • @tcaswell: Yeah, it's weird. It used to work find and I'm not sure what I did in the meantime (nothing I can recall) — *maybe* and update of some part of the stack using pip. – orome Oct 27 '13 at 19:36
  • @tcaswell: Looking at the builds on [source forge](http://sourceforge.net/projects/numpy/files/NumPy/), I'm guessing that 1.8 (the "version 8" referred to in the error message?) is soon to appear through pip and that the error will go away then. At least, I bet waiting for that is probably worth doing. – orome Oct 27 '13 at 19:40
  • My uninfromed guess is that when you updated to maverics, it installed a version of python + numpy and set the paths so that you are using _apple's_ version of python, where as however you installed python before you were using the python.org version (or what ever magic was done by the original installer). My advise would be to remove everything you can and start from scratch. Enthought has a nice bundle that updates regularly and they pay people to fight osx for you ;) – tacaswell Oct 27 '13 at 19:41
  • 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. – orome Oct 27 '13 at 19:46
  • If you reinstall matplotlib, and it still complains about the wrong version, the only possible explanation is that you indeed have two versions of Numpy installed somewhere on your computer. You should look in all directories listed by `import sys; print("\n".join(sys.path))` and check that neither Numpy or matplotlib is in any of them. After that, you can reinstall first Numpy and then matplotlib. – pv. Oct 29 '13 at 18: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? – orome Oct 29 '13 at 19:39
  • Based on the information you give here, it's impossible to say what is/was wrong in your installation. – pv. Oct 29 '13 at 20:32
  • @pv.: What can I add to help. – orome Oct 29 '13 at 20:37
  • You could try installing matplotlib with MacPorts. – Javier Castellanos Dec 08 '13 at 00:40
  • I've got the same problem and `sudo pip install -U --force-reinstall scipy` and then a restart on the machine works =) – alvas Dec 28 '13 at 19:57

5 Answers5

6

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

sudo pip install -U --force-reinstall scipy
orome
  • 45,163
  • 57
  • 202
  • 418
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.

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!

alexfigtree
  • 1,516
  • 14
  • 16
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 :)

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__

Community
  • 1
  • 1
Marco
  • 11
  • 2