2012-09-06 54 views
1

我創建了一個使用Matplotlib/mathtext字體的wxapp,並將它轉換爲一個帶有py2exe的exe文件。結果EXE運行罰款在我的電腦上。Matplotlib,py2exe中的mathtext findfont問題應用程序

~\dist\library.zip\matplotlib\font_manager.py:1216: UserWarning: findfont: Font family ['STIXGeneral'] not found. Falling back to Bitstream Vera Sans 
~\dist\library.zip\matplotlib\font_manager.py:1226: UserWarning: findfont: Could not match :family=Bitstream Vera Sans:style=normal:variant=normal:weight=normal:stretch=normal:size=12. Returning c:\windows\fonts\browai.ttf 
~\dist\library.zip\matplotlib\font_manager.py:1216: UserWarning: findfont: Font family ['STIXSizeOneSym'] not found. Falling back to Bitstream Vera Sans 
~\dist\library.zip\matplotlib\font_manager.py:1226: UserWarning: findfont: Could not match :family=Bitstream Vera Sans:style=normal:variant=normal:weight=bold:stretch=normal:size=12. Returning c:\windows\fonts\browai.ttf 
~\dist\library.zip\matplotlib\font_manager.py:1216: UserWarning: findfont: Font family ['STIXSizeThreeSym'] not found. Falling back to Bitstream Vera Sans 
~\dist\library.zip\matplotlib\font_manager.py:1216: UserWarning: findfont: Font family ['STIXSizeFourSym'] not found. Falling back to Bitstream Vera Sans 
~\dist\library.zip\matplotlib\font_manager.py:1216: UserWarning: findfont: Font family ['STIXSizeFiveSym'] not found. Falling back to Bitstream Vera Sans 
~\dist\library.zip\matplotlib\font_manager.py:1216: UserWarning: findfont: Font family ['STIXSizeTwoSym'] not found. Falling back to Bitstream Vera Sans 
~\dist\library.zip\matplotlib\font_manager.py:1226: UserWarning: findfont: Could not match :family=Bitstream Vera Sans:style=italic:variant=normal:weight=normal:stretch=normal:size=12. Returning c:\windows\fonts\browai.ttf 
~\dist\library.zip\matplotlib\font_manager.py:1216: UserWarning: findfont: Font family ['STIXNonUnicode'] not found. Falling back to Bitstream Vera Sans 
~\dist\library.zip\matplotlib\font_manager.py:1216: UserWarning: findfont: Font family ['cmb10'] not found. Falling back to Bitstream Vera Sans 
~\dist\library.zip\matplotlib\font_manager.py:1216: UserWarning: findfont: Font family ['cmtt10'] not found. Falling back to Bitstream Vera Sans 
~\dist\library.zip\matplotlib\font_manager.py:1216: UserWarning: findfont: Font family ['cmmi10'] not found. Falling back to Bitstream Vera Sans 
~\dist\library.zip\matplotlib\font_manager.py:1216: UserWarning: findfont: Font family ['cmex10'] not found. Falling back to Bitstream Vera Sans 
~\dist\library.zip\matplotlib\font_manager.py:1216: UserWarning: findfont: Font family ['cmsy10'] not found. Falling back to Bitstream Vera Sans 
~\dist\library.zip\matplotlib\font_manager.py:1216: UserWarning: findfont: Font family ['cmr10'] not found. Falling back to Bitstream Vera Sans 
~\dist\library.zip\matplotlib\font_manager.py:1216: UserWarning: findfont: Font family ['cmss10'] not found. Falling back to Bitstream Vera Sans 

而且我也看到了這結尾的回溯:

... 
File "matplotlib\mathtext.pyo", line 720, in _get_glyph 
KeyError: 98 

無法找到的字體,但是我把它在其他地方,當它與app.exe.log以下崩潰都由matplotlib/mathtext使用。

我發現setup.py中的兩個方法,我嘗試獲取data_files(使用glob和matplotlib.get_py2exe_datafiles)沒有工作,沒有什麼複製到我的mpl-data/fonts目錄。源目錄:C:\ Python27 \ Lib \ site-packages \ matplotlib \ mpl-data \ fonts包含3個文件夾:afm,pdfcorefonts & ttf。 ttf文件夾是上面提到的mathtext字體所在的位置。

我試着手動將整個mpl-data文件夾複製到dist文件夾中,然後在setup.py上運行py2exe並修改glob以獲得3字體目錄,但仍然得到相同的錯誤。

看來,matplotlib的font_manager中的findfont方法在通過py2exe運行後無法工作,我猜測mathtext.pyo中的_get_glyph嘗試使用Bitstream Vera Sans字體時會崩潰。

+0

您可能會給'pyinstaller'試試吧。我發現默認情況下它比mat2更友好,而不是'py2exe'。 http://www.pyinstaller.org/ –

+0

我已經嘗試pyinstaller快速使用默認值,它也崩潰在新的機器上,但沒有日誌。你知道如何讓exe生成一個日誌或使窗口打開pyinstaller? – Jonno

+0

沒關係,我正在變厚。從cmd行運行我得到與pyinstaller相同的錯誤: – Jonno

回答

0

使用matplotlib.get_py2exe_datafiles()對我來說工作正常。只要確保你使用的是最新版本的matplotlib的和setup.py使用它像這樣:

datafiles = matplotlib.get_py2exe_datafiles() 

setup(... 
     ... 
     data_files = datafiles, 
     ... 
    )