2016-05-17 19 views
1

當我嘗試以下方法(在Python 3):ttf_lookup_cache屬性不FontManager發現

>>> import matplotlib.pyplot as pl 
>>> pl.plot([1, 2, 3]) 
>>> pl.show() 

我得到一個錯誤,並在最後:

AttributeError: 'FontManager' object has no attribute 'ttf_lookup_cache' 

但是,當我下面的工作原理:

>>> from matplotlib.font_manager import FontManager 
>>> FontManager().ttf_lookup_cache 
{} 

FontManager構造需要一定的時間(1.5秒〜),而第一個代碼不。

而且,上面的代碼工作與Python 2完全沒有問題,我發現了一些帖子,詢問類似的問題,如:

...但沒有的答案爲我工作。

如果有幫助,我正在使用python 3.4.3和matplotlib 1.3.1的Ubuntu 14.04.4。

回答

1

經過大量的挖掘,我意識到問題可能是我使用的matplotlib的舊版本(使用apt-get install安裝)。我試着刪除它,並用pip安裝它和它的工作:

sudo apt-get remove python3-matplotlib 
sudo pip3 install matplotlib 

在那之後,我得到了一個警告,我第一次進口matplotlib.pyplot(關於建立字體緩存)。現在一切正常。

的使用pip3matplotlib已安裝的版本1.5.1 (從apt1.3.1使用)。