input

Distributing Python Scripts – the Batchtraveller.app

This is a short intro on how Python-scripts can be packaged into an easy to distribute mac-app.

Essentially I followed two tutorials. The first on how to turn your python script into a self-contained app, the second on how to make compressed diskimages for mac. The final result aswell as the files necessary to reproduce the steps can be downloaded here. A detailed desription can be found in the remainder of this post.

0. Make a nice skript

I used my previous python skript that batch-queries google maps to gather distances and travel times between a start and an end-address. I added two guis one that asks for the input file and one that asks for the location where results should be stored.

1. Use py2app to compile the binary

The package py2app (install/upgrade with “easy_install -U py2app”) is a package that automatically gathers all necessary packages and builds an app. It is employed in two steps:

1.1. Make a setup.py file:

This can be done with the following command:

?Download XXX.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<blockquote>py2applet --make-setup Batchtraveller.py</blockquote>
 
#As mine resulted in an errors, I had to add the option argv_emulation: False.
<blockquote>"""
This is a setup.py script generated by py2applet
 
Usage:
python setup.py py2app
"""
 
from setuptools import setup
 
APP = ['Batchtraveller.py']
DATA_FILES = []
<strong>OPTIONS = {'argv_emulation': False}</strong>
 
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)</blockquote>

1.2. Build the app:

To build the app (with a nice icon), the following command was used:

python setup.py py2app –iconfile browser.icns

This results in two new folders “built” and “dist”, the latter of which contains the Batchtraveller.app.

2. Make a “standard” compressed *.dmg

Instead of just giving the application away, I wanted to make a compressed diskimage, that contains the file, the licence-information and a shortcut to the applications directory. So here is what I did.

  1. I made a new diskimage of roughly the same size as the files using the Mac Disk Utility.
  2. Then I copied the *.app and licence.txt files into the disk image, and made a shortcut to the Applications directory.
  3. I used the Disk Utility again to convert the diskimage to a compressed dmg.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>