Using app2py for OS X Distribution

I thought that .pex files were the way to go for distributing Python applications to OS X users, but it was only partially successful. For one, users needed to reinstall Python with Homebrew, which isn’t difficult, it’s just awkward explaining to people that the Python distribution that ships with Mac isn’t the same Python distribution that exists in the wild. Their next question is invariably, “how will this affect the rest of my system?” I can’t answer that. I can’t guarantee that things will be future-proof.

And then I found app2py (or five dollars) which creates a Mac application bundle out of a Python script. It worked like a charm. The best thing is that you don’t have to write a stupid setup.py file, it writes one for you. That’s five minutes of your precious time you can look at cat videos with, or whatever.

You can install this using pip, so that’s cool. Next, you do as the tutorial explains,

py2applet --make-setup MyApplication.py

This will create a setup.py file. Finally, for deployment, you build the distribution with a non-Mac Python installation. (If you haven’t already run brew install python you’ll want to run that.) My brew installation of the Python landed somewhere in /usr/local/Cellar/....

/usr/local/Cellar/python/2.7.8_2/bin/python setup.py py2app

This will create a standalone Python application that you can distribute painlessly to your Mac colleagues.