anti-particle.com
Home  About  Old News  Links 
 Become The Media A "100% Vegan" Production 
. : py2exe how-to : .

. : Python : .
» pygtk / py2exe 0.4.x how-to
  How-to build standalone windows executables for GTK+2.0 using py2exe 0.4.x
» pygtk / py2exe 0.5.x how-to
  How-to build standalone windows executables for GTK+ 2.2 or 2.4 using py2exe 0.5.x
   
 
. : Overview : .
Here's a How-To on generating stand-alone executables for pygtk programs using py2exe 0.4.x  Any comments, please email me: py2exe at anti-particle dot com
 
. : Initial Installation (Windows OS): .
1) Install the latest version of python. You may need to add the install location to your PATH environment variable...
  e.g. c:\python23
2) Install the latest version of GTK for windows. Add the locations of the bin and lib folders to your PATH environment variable...
  e.g. c:\Program Files\Common Files\GTK\2.0\bin
  e.g. c:\Program Files\Common Files\GTK\2.0\lib
3) Install the latest version of pygtk for windows.
4) Install py2exe.
5) Install the installer! Inno Setup.
6) A useful extra is ISTool which can edit the scripts Inno Setup produces.
 
. : Configure your project : .
The code where gtk and pygtk get imported into your project should look something like:
import pygtk
#this is needed for py2exe
if sys.platform == 'win32':
    #win32 platform, add the "lib" folder to the system path
    os.environ['PATH'] += ";lib;"
else:
    #not win32, ensure version 2.0 of pygtk is imported
    pygtk.require('2.0')
import gtk
import gobject
assert gtk.pygtk_version >= (1,99,16), 'pygtk should be >= 1.99.16'
import gtk.glade
 
. : Configure py2exe for your project : .
1) Build a setup.py file. Here is one I used for The Pycadia Project:
from distutils.core import setup
import py2exe
import glob

setup(
    name="pycadia",
    scripts=["pycadia.py"],
    data_files=[("pycadia.conf"),
                ("pixmaps", glob.glob("pixmaps/*.png")),
                ("sounds", glob.glob("sounds/*.wav")),
                ("glade", glob.glob("glade/*.*"))
    ]
)
 
2) Build a setup.cfg file. Here is an example:
[py2exe]
includes=atk,pango
icon=an_icon.ico
version-companyname=www.anti-particle.com
version-legalcopyright=2003 Fingal McFungal
version-filedescription=The Project Title
version-fileversion=1.0.0
version-productname=project_name_here
version-productversion=1.0.0
 
. : Build the executable : .
From a command prompt in your project_name folder, run:
python setup.py py2exe --force --windows
This should create a dist\project_name folder in your project folder.
 
. : Supplementary files : .
Copy the GTK subfolders etc and lib to your dist\project_name folder.
e.g.:
copy c:\Program Files\Common Files\GTK\2.0\etc dist\project_name
copy c:\Program Files\Common Files\GTK\2.0\lib dist\project_name
At this point you should have something that works. Try it out by copying the dist\project_name folder to a clean PC and giving it a go...
 
. : Build the installer : .
Watch this space...
 
. : Last update: Friday, 14-Jun-2013 16:11:26 BST : .
Initial Design: Copyleft © 02001 Jaden
The Rest: Copyleft © 02002-02006 Andy Balcombe