Friday, January 30, 2009

Using py2exe for PyGTK apps

Here's a simple setup.py file that does most of the work (obviously, you'll have to edit the variables at the start):


from distutils.core import setup
import py2exe

appname = "Application Name"
appdescription = "A description of what the application does"
scriptname = "the-script-name.py" #the python script to compile
iconfile = "the-application-icon.ico" #must be a .ico

setup(
name = appname,
description = appdescription,
version = '1.0',

windows = [
{
'script': scriptname,
'icon_resources': [(1, iconfile)],
}
],

options = {
'py2exe': {
'packages':'encodings',
'includes': 'cairo, pango, pangocairo, atk, gobject'
}
}
)


When you've run it, copy the folders etc, lib, and share from your installation of GTK (not PyGTK) into the dist folder the script created. You can prune their contents judiciously if you know what you're doing, but this will let GTK find the theme and other files it needs.




EDIT: Note that py2exe seems to have problems with Python 2.6. I'd recommend sticking to 2.5 for whatever machine you build Windows executables.

No comments: