简体   繁体   English

无法导入matplotlib

[英]Can't import matplotlib

I installed matplotlib using the Mac disk image installer for MacOS 10.5 and Python 2.5. 我使用适用于MacOS 10.5和Python 2.5的Mac磁盘映像安装程序安装了matplotlib。 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 我安装了numpy,然后尝试导入matplotlib,但收到此错误: ImportError: numpy 1.1 or later is required; you have 2.0.0.dev8462 ImportError: numpy 1.1 or later is required; you have 2.0.0.dev8462 . 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. 似乎2.0.0.dev8462版本晚于1.1版本,但是我猜想matplotlib与该版本中的“ .dev8462”混淆了。 Is there any workaround to this? 有什么解决方法吗?

Here is the troublesome code located in Lib/site-packages/matplotlib/__init__.py in my python distribution on Windows 这是我在Windows上的python发行版中的Lib/site-packages/matplotlib/__init__.py中的麻烦代码

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 问题在于,它要求第一个数字到第一个数字(用句点分隔)都必须大于或等于1,并且在您的情况下,第二个数字必须是2。您可以通过多种方法来解决此问题,但是有一种方法是将if语句更改为

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. 可能更好。

Following Justin's comment ... here is the equivalent file for Linux: 跟随贾斯汀的评论...这是Linux的等效文件:

/usr/lib/pymodules/python2.6/matplotlib/__init__.py

sudo edit that to fix the troublesome line to: if not ((int(nn[0]) >= 1 and int(nn[1]) >= 1) or int(nn[0]) >= 2): sudo编辑以将麻烦的行修复为:如果不是((int(nn [0])> = 1且int(nn [1])> = 1)或int(nn [0])> = 2):

Thanks Justin Peel! 谢谢贾斯汀·皮尔!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM