1
votes

I've created a wxapp which uses Matplotlib/mathtext fonts and converted it into an exe with py2exe. The resultant exe runs fine on my pc. However when I take it elsewhere it crashes with the following in 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

And I also see a traceback which ends with:

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

The fonts that can't be found are all used by matplotlib/mathtext.

I discovered that both the methods within setup.py I tried for getting data_files (using glob and matplotlib.get_py2exe_datafiles) were not working and nothing was getting copied to my mpl-data/fonts directory. The source directory: C:\Python27\Lib\site-packages\matplotlib\mpl-data\fonts contains 3 folders: afm, pdfcorefonts & ttf. The ttf folder is where the mathtext fonts mentioned above are located.

I tried manually copying the entire mpl-data folder into the dist folder after running py2exe on setup.py and also modifying glob to get the 3 font directories but still I get the same error.

It seems that the findfont method in matplotlib's font_manager isn't working after running through py2exe and I guess when _get_glyph in mathtext.pyo attempts to use Bitstream Vera Sans font it crashes.

1
You might give pyinstaller a try instead. I've found it to be more matplotlib-friendly by default than py2exe. pyinstaller.orgJoe Kington
I've tried pyinstaller quickly with the defaults and it also crashes on a fresh machine but without a log. Do you know how to have the exe produce a log or keep the window open in pyinstaller?Jonno
Never mind I was being thick. Running from cmd line I get the same errors with pyinstaller:Jonno
I'm at a loss, then. You've done a good job of finding what appears to be the root problem (findfont not working). You might ask on the py2exe or pyinstaller mailing lists. Good luck, at any rate!Joe Kington

1 Answers

0
votes

Using matplotlib.get_py2exe_datafiles() is working fine for me. Just make sure you are using the latest version of matplotlib and use it like so in setup.py:

datafiles = matplotlib.get_py2exe_datafiles()

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