CS 121 -- Fall 2012


Creating a Python Executable

1. Overview

You need: Make sure the version of py2exe/ py2app matches the version of Python that they have!

The code for using py2exe. Note: read all the comments, especially the one about saving a copy of you python code prior to creating the executable. Basically, you put the above code in a Python file in the same folder as the game. Change self.script to be the name of your primary Python file (e.g. "main.py"). self.extra_datas also has to be changed to include images, music, custom fonts, etc. self.script will accept folder names. So, for example, if all of your images are in a folder called "images" and all the music is in a folder called "sounds", the line should be self.extra_datas = ["images", "sounds"]. An official py2app tutorial . The tutorial recommends using py2applet, a py2app terminal command that theoretically does all of the work. If it does not work, it is pretty simple to handwrite the script generated by py2applet. Here's the one used for Binary Bubbles:

Usage:
python setup.py py2app

from setuptools import setup APP = ['BBuilder.py'] DATA_FILES = ['fonts', 'images', 'sounds'] OPTIONS = {'argv_emulation': False} setup( app=APP, name='BBuilder', data_files=DATA_FILES, options={'py2app': OPTIONS}, setup_requires=['py2app'], ) When all else fails, try Googling.

Mike Erlinger

Last Modified Tuesday, 06-Nov-2012 14:05:14 PST