1

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.

4
  • You might give pyinstaller a try instead. I've found it to be more matplotlib-friendly by default than py2exe. pyinstaller.org Commented Sep 7, 2012 at 15:49
  • 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? Commented Sep 7, 2012 at 18:50
  • Never mind I was being thick. Running from cmd line I get the same errors with pyinstaller: Commented Sep 7, 2012 at 19:12
  • 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! Commented Sep 7, 2012 at 19:26

1 Answer 1

0

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,
      ...
     )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.