views:

53

answers:

1

I installed matplotlib using the Mac disk image installer for MacOS 10.5 and Python 2.5. I installed numpy then tried to import matplotlib but got this error: ImportError: numpy 1.1 or later is required; you have 2.0.0.dev8462. It seems to that version 2.0.0.dev8462 would be later than version 1.1 but I am guessing that matplotlib got confused with the ".dev8462" in the version. Is there any workaround to this?

+1  A: 

Here is the troublesome code located in Lib/site-packages/matplotlib/__init__.py in my python distribution on Windows

nn = numpy.__version__.split('.')
if not (int(nn[0]) >= 1 and int(nn[1]) >= 1):
    raise ImportError(
            'numpy 1.1 or later is required; you have %s' % numpy.__version__)

The problem is that it is requiring both the first to digits (separated by periods) to be greater than or equal to 1 and in your case the second digit is a 2. You can get around this in a number of ways, but one way is to change the if statement to

if not ((int(nn[0]) >= 1 and int(nn[1]) >= 1) or int(nn[0]) >= 2):

or you could just change it to:

if not (float('.'.join(nn[2:])) >= 1.1):

which might be better.

Justin Peel
+1. But here is a simpler version: `(int(nn[0]), int(nn[1])) >= (1, 1)`. In fact, tuples compare with the so-called "dictionary order".
EOL