代码之家  ›  专栏  ›  技术社区  ›  None

无法导入matplotlib

  •  1
  • None  · 技术社区  · 16 年前

    我使用macos10.5和python2.5的Mac磁盘映像安装程序安装了matplotlib。我安装了numpy,然后尝试导入matplotlib,但出现以下错误: ImportError: numpy 1.1 or later is required; you have 2.0.0.dev8462

    2 回复  |  直到 16 年前
        1
  •  1
  •   Justin Peel    16 年前

    下面是位于 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__)
    

    问题是,它要求第一个到第二个数字(用句点分隔)大于或等于1,在您的情况下,第二个数字是2。您可以用多种方法来解决这个问题,但有一种方法是将if语句改为

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

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

    哪种可能更好。

        2
  •  0
  •   HaoQi Li    15 年前

    听了贾斯汀的评论。。。以下是Linux的等效文件:

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

    如果不是((int(nn[0])>=1和int(nn[1])>=1) 或int(nn[0])>=2):

    谢谢贾斯汀·皮尔!