Packaging a python app for windows

Hello everyone. I am working on a group project this semester using tensorflow and tflearn to build a small application that lets users train generative NN models on hip hop lyrics and then apply some relevant hip hop post processing.

Good news: the application is 80% written and all of the tricky stuff is done, we've got a couple weeks to wrap up the last 20%.

Bad new: we have to package it for use on our professors windows box in his office.

I've written lots of python scripts and small projects but I've never packaged an 'app' for distribution. Could someone just walk me through the steps? I know there is a lot of information online but it's not clear to me how much applies to our situation or not.

In an ideal world we would just package everything into something like a .jar that our professor could run and would 'just work'. I know there is probably not a direct python equivalent to this, but is there a way to give him a package with an .exe or something?

Any pointers, or good resources would be appreciated. Thanks!

Posted Apr 14, 2017, 3:51 PM UTC

32
novel_yet_trivial•

the application is 80% written and all of the tricky stuff is done, we've got a couple weeks to wrap up the last 20%.

Bwahahahaha!

Sorry, buddy, every programmer knows the last 10% of a project takes 90% of your time ...


The equivalent to a .jar file is a .egg file. Make a file called __main__.py that launches your program, put that into a zip file along with all the support files you need, and rename the zip to a .egg extension. Then python can run it.

If you want to make an .exe you need to look into freezing programs like pyinstaller or cx_freeze. Here's a quick overview. These will make a one .exe file and a folder with dozens to hundreds of support files (depending on what your program imports). If you want a single .exe file you need to bundle all of the support files into a self-extracting zip file.Some freezing programs have this option as a "one file" option or you can do it yourself. The problem is that every time your program is run, those support files need to be unzipped into a temporary folder, which slows your boot time a lot.

Python is based on the idea that instead of an installer for each program, you install python and the python program itself is (often) system agnostic. So I would try to get your prof to install python and just give him the .py file. (After all you have to install Java to run a .jar).

Another option is pynsist to make an installer that bundles your python file and the python support files. In other words it includes a light python installation. This does not freeze your files but it is still OS specific.

3
JVO1317•

For side projects I've used py2exe. More recently I changed to pyInstaller because openpyxl doesn't work in py2exe.

With pyInstaller you can package your whole project in a single exe file (4Mb or more because it includes the whole Python interpreter and required libraries) that you can distribute.

1