Packaging Gooey as a Distributable Application

For packaging, Gooey supports two options: CxFreeze, and PyInstaller. We're going to focus on PyInstaller as it's my preferred wrapper due to its ability to make end user friendly single file executables on Windows, OSX, and Linux. Meaning, this:

Instead of this:

Prerequisites

If you don't already have it, download the latest PyInstaller version and install it via setuptools.

Step 1: Preparing your script for packaging.

By default, the python interpreter buffers stdout. In short, this means that rather than Gooey being able to read the output of your program in real time, it receives it in very coarsely grained chunks.

Normally, passing the -u flag to the Python interpreter would be enough to prevent stdout buffering. However, due to an apparent quirk in PyInstaller, it seems that the -u flag never makes its way up to the interpreter, and thus the output is still highly buffered. Luckily, getting around this pretty easy.

For the most part, this is the default spec file which PyInstaller generates. However, there are a few modification to instruct PyInstaller to pull in all of the non-code resources used by Gooey. Credit goes to roshgar for figuring this all out!

With this spec, you'll just need to make two changes:

Update the application path in the Analysis constructor to point at your Python script

update the name argument in the EXE constructor to the name of your program.

Step 3: Build your project

The final step is to feed the spec file to PyInstaller and let it do its magic.

Open a terminal in the directory with your spec file and enter

pyinstaller build.spec

Done!

PyInstaller will stick your packaged executable in a directory called dist. Open that up and you'll find your shiney new app all ready to distribute.