Skip to content

Packaging an application with py2app (or py2exe)

pboucher edited this page Feb 22, 2013 · 2 revisions

You can create standalone applications with Python scripts by using py2app on OSX or py2exe on Windows. This is often done to more easily distribute applications that have a GUI based on toolkits like Tk, Qt or others.

There are caveats you need to be aware of when creating such an app.

HTTPS Validation and cacerts.txt

When creating the connection to Shotgun a file is used to validate the Shotgun certificate. This file is shotgun_api3\lib\httplib2\cacerts.txt. Because this file is not a Python file imported by your application, py2app will not know to include it in your package, it will need to be explicitly specified in your setup.py file (edit the path based on the location where your shotgun_api3 package is located).

DATA_FILES = [
    ('shotgun_api3', ['/shotgun/src/python-api/shotgun_api3/lib/httplib2/cacerts.txt'])
]

Once you create your py2app package its contents should include two files (among others) in the following structure:

./Contents/Resources/shotgun_api3/cacerts.txt
./Contents/Resources/my_script.py

Where in my_script.py you can access the cacerts.txt file using a relative path to pass it into the Shotgun connection's constructor:

ca_certs = os.path.join(os.path.dirname(__file__), 'shotgun_api3', 'cacerts.txt')
sg = shotgun_api3.Shotgun('https://yoursite.shotgunstudio.com', 'script_name', 'script_key', ca_certs=ca_certs)

The process for py2exe should be similarly simple.

Clone this wiki locally