2010-06-14 85 views
1

我使用適用於MacOS 10.5和Python 2.5的Mac磁盤映像安裝程序安裝了matplotlib。我安裝numpy然後試圖導入matplotlib但得到這個錯誤:ImportError: numpy 1.1 or later is required; you have 2.0.0.dev8462。看來版本2.0.0.dev8462會晚於版本1.1,但我猜測matplotlib與版本中的「.dev8462」混淆了。有沒有解決這個問題的方法?無法導入matplotlib

+1

Numpy 2.0不與matplotlib向後兼容,如果您嘗試在其上運行matplotlib,它將會*崩潰。如果你想運行numpy 2. *,你需要重建每個使用numpy C API(matplotlib,scipy等)的包。 – 2010-06-14 06:40:37

回答

1

這裏是位於Lib/site-packages/matplotlib/__init__.py在我的Python分佈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__) 

的問題是,它需要同時第一至數字(由句點分隔)爲大於或等於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): 

這可能會更好。

+0

+1。但是這是一個更簡單的版本:'(int(nn [0]),int(nn [1]))> =(1,1)'。實際上,元組與所謂的「字典順序」相比較。 – EOL 2010-06-14 08:41:54

0

繼賈斯汀的評論...這裏是Linux的相應文件:

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

sudo的編輯來解決麻煩的線路: 如果不是((INT(NN [0])> = 1和int(nn [1])> = 1)或int(nn [0])> = 2):

謝謝Justin Peel!