Font Errors: PyInstaller + matplotlib

If you ever want to deliver a standalone Python-based app that doesn’t require a full-blown Python install, have a look at PyInstaller.  It’s just about the most painless way I know of to do it and it supports a ton of Python libs right out of the box.  If you don’t see your package listed there, go ahead and try it since there’s a good chance it’ll work anyway- I found that the Excel spreadsheet lib xlrd works without a hitch, for example.

One thing I did discover this morning though about matplotlib – on Windows at least (I haven’t confirmed for other platforms), matplotlib keeps a font cache under the .matplotlib folder that points to font installations.  I put together a wxPython + matplotlib + xlrd app that worked fine with PyInstaller but I couldn’t figure out why it wouldn’t plot data it pulled from the Excel spreadsheets.  Looking at the debug messages, matplotlib seemed to be complaining that it couldn’t find the Vera font; PyInstaller knows to include the fonts with the frozen app so it looked like matplotlib wasn’t looking in the right place.

It turned out matplotlib’s font cache was pointing to a non-existent folder – delete the cache and the app worked as advertised on next startup.  In my case, it hit me because I used to have matplotlib installed as part of my Python installation but I later removed it; but you might also run into it if you’ve run and removed other matplotlib-based applications.  I’m sure there’s a better fix than the one I’ve outlined but I thought I’d post my findings in case anyone else comes across this same problem.

Comments are closed.