Using py2exe and Inno Setup with PyQT and Matplotlib

Happy New Year! I seem to have some good momentum going into 2008. Hopefully I can keep things rolling along.

I wrapped the 0.2 release of Delphos into an installer yesterday using Inno Setup. I did this by combining my existing py2exe build script with a sample script from the py2exe code repository. This sample first runs py2exe and then generates a build script for Inno Setup on the fly and passes it to the Inno Setup compiler. Source to installer in one shot!

The biggest issue was getting matplotlib to play nice. PyQt, SqlAlchemy and the other modules had no problem. Matplotlib requires additional data files to be packaged into the py2exe build, multiple directories worth in fact with their own subdirectories and files. Matplotlib has a function that tells you exactly what supplementary data files it needs (called get_py2exe_datafiles), but it didn’t work correctly for me (see this thread). So, until now I would just copy them all into a new build by hand but now I needed Inno Setup to know about each of these files too so it could bundle them into the installer. In this case the handoff from py2exe to Inno Setup is automated so the solution was to tell py2exe about the additional data files and that information would get passed on to be included in the Inno Setup build script that’s generated.

One solution was to list every data file by hand in the py2exe portion of the build script, but geez what a tedious waste of time. This kind of stuff changes regularly so it had to be automated as much as possible. Unfortunately, telling py2exe about multiple directories worth of data files to include isn’t easy. It seems distutils, which py2exe runs on top of, can only be given a list of individual files to include with the build. You can’t (that I know of) simply give it a directory path and it will recursively include all directories and files underneath.

Thankfully I found a nice little function on the net from a guy named jt (referenced in the build script) that walks a directory structure and builds a list of file names and paths in the form that py2exe expects. I used that same function to package all of my documentation files and other boilerplate stuff with the build. Very slick. I had to make a quick fix to it though as the function was mistaking directories for files in some cases. Py2exe handled this fine but InnoSetup would error if asked to copy a directory when expecting a file. So, I essentially massacred a sweet little 2 line piece of functional programming goodness and dropped in a ‘quick’ fix. Time is short ya know…

The py2exe/Inno Setup build script can be found here.

One Response to “Using py2exe and Inno Setup with PyQT and Matplotlib”

  1. Recent Faves Tagged With "matplotlib" : MyNetFaves Says:

    [...] public links >> matplotlib Using py2exe and Inno Setup with PyQT and Matplotlib First saved by juxjux | 2 days ago On how to define an ODE system in matplotlib First saved by [...]

Leave a Reply