Matplotlib,在py2exe应用程序中的mathtext findfont问题

时间:2012-09-06 20:08:48

标签: latex matplotlib wxpython py2exe

我创建了一个wxapp,它使用Matplotlib / mathtext字体并将其转换为带有py2exe的exe。结果exe在我的电脑上运行正常。但是,当我把它带到其他地方时,它会在app.exe.log中崩溃:

~\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

无法找到的字体全部由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字体所在的位置。

我尝试在setup.py上运行py2exe后手动将整个mpl-data文件夹复制到dist文件夹中,并修改glob以获取3个字体目录,但我仍然得到相同的错误。

似乎matplotlib的font_manager中的findfont方法在运行py2exe后无效,我想当mathtext.pyo中的_get_glyph尝试使用Bitstream Vera Sans字体时会崩溃。

1 个答案:

答案 0 :(得分:0)

使用matplotlib.get_py2exe_datafiles()对我来说很好。请确保您使用的是最新版本的matplotlib并在setup.py中使用它:

datafiles = matplotlib.get_py2exe_datafiles()

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