Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fixing matplotlib/numpy dependency hell in Anaconda

I'm running Python 2.7.11 under Anaconda 2.0.0 (x86_64) on a MacBook.

Some weeks ago, as part of a process of getting OpenCV working, I downgraded numpy from wherever it was (unfortunately/stupidly I have no record) to 1.7.1. I seem to remember this was necessary, and I do not want OpenCV to stop working, so I'm pretty sure I should now leave numpy where it is.

However, today I discovered that this has broken my matplotlib/pylab. When I do import pylab I get the following:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
RuntimeError: module compiled against API version 9 but this version of numpy is 7
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)    
...
...
ImportError: numpy.core.multiarray failed to import

My question, therefore, is: how do I install (or roll back to) a version of matplotlib that's compatible with my existing numpy, without disturbing my existing numpy?

Here's where I've got so far: based on related conda questions on SO, I looked at the output of conda list --revisions matplotlib which includes:

...
2016-03-28 17:16:36  (rev 6)
     conda  {3.8.3 -> 4.0.5}
     conda-env  {2.0.1 -> 2.4.5}
     numpy  {1.8.1 -> 1.7.1}
     ...

Now I'm not sure how to interpret this but given the numpy version number looks like it's actually falling in contrast to all the other entries here, this sounds to me like a promising, "in March 2016 matplotlib realized it could fall back to an earlier version of its numpy dependency". However, when I ask for this revision:

conda install --revision=6 matplotlib

I'm told I already have it, and that its dependency is numpy 1.8:

Fetching package metadata: ....

# All requested packages already installed.
# packages in environment at /Users/jez/anaconda:
#
matplotlib                1.3.1                np18py27_1    <unknown>

So from here I'm not sure how to proceed. I've tentatively played with some variations on conda install matplotlib, but it clearly wants to mess with my numpy at the same time, so I have never pressed y. Equally clearly, I'm out of my depth in conda, so would really appreciate your help.

like image 989
jez Avatar asked Apr 22 '16 16:04

jez


1 Answers

You can specify the exact versions of any libraries you want in the conda install command. For example:

$ conda install numpy=1.7.1 matplotlib=1.3

If the versions are incompatible, the command will give you an error specifying exactly what the incompatibility is.

like image 123
jakevdp Avatar answered Sep 26 '22 00:09

jakevdp