After writing an application, you may want to distribute it to users who do not have Python and wxPython installed.

Packaging your Application for Windows Users

For converting your application to Windows executable format, look no further than py2exe (

  1. Make sure that you have distutils installed (if you have a recent Python version, you most likely do). DO NOT install distutils if you already have it, because then you will get cryptic errors later on.
  2. Download and install py2exe.
  3. Navigate to your application directory (the one with your main Python file), and create a file called ''.
  4. Copy and paste the following into your

   1 #!/usr/bin/python
   3 from distutils.core import setup
   4 import py2exe
   6 manifest = """
   7 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
   8 <assembly xmlns="urn:schemas-microsoft-com:asm.v1"
   9 manifestVersion="1.0">
  10 <assemblyIdentity
  11     version=""
  12     processorArchitecture="x86"
  13     name="Controls"
  14     type="win32"
  15 />
  16 <description>Your Application</description>
  17 <dependency>
  18     <dependentAssembly>
  19         <assemblyIdentity
  20             type="win32"
  21             name="Microsoft.Windows.Common-Controls"
  22             version=""
  23             processorArchitecture="X86"
  24             publicKeyToken="6595b64144ccf1df"
  25             language="*"
  26         />
  27     </dependentAssembly>
  28 </dependency>
  29 </assembly>
  30 """
  32 """
  33 installs manifest and icon into the .exe
  34 but icon is still needed as we open it
  35 for the window icon (not just the .exe)
  36 changelog and logo are included in dist
  37 """
  39 setup(
  40     windows = [
  41         {
  42             "script": "",
  43             "icon_resources": [(1, "yourapplication.ico")],
  44             "other_resources": [(24,1,manifest)]
  45         }
  46     ],
  47       data_files=["yourapplication.ico"]
  48 )

Looking at the examples on the py2exe website, you may wonder why there is so much more text in this file. When you use wxPython and py2exe on Windows, you need to include the manifest file - that's what the manifest thing is.

  1. I'm sure your main Python file isn't called "", so change the names in accordingly. If you don't have an icon for your application, you can delete the "icon_resources" and data_files fields. However, I suggest that you find and use an icon, because then your executable looks more inviting.
  2. Using the command line, navigate to your application directory and type in "python py2exe". py2exe detects all the dependencies and creates the executable, so you need not worry about specifying the libraries you used.
  3. After it's done, look in your application directory for a directory called "dist", generated by py2exe. In it should be your executable file, if all went well.

It's so... big!

Yes, the generated files tend to be somewhat bulky, but that's the price you pay for giving your users the bare bones of wxPython, Python, and all the other libraries you've used. However, you can significantly cut your application down to size using certain techniques, which are contained in the following batch file:

@echo off 

"C:\Python24\python.exe" py2exe

cd dist

"C:\Program Files\7-Zip\7z.exe" -aoa x -olibrary\ 
cd library\ 
"C:\Program Files\7-Zip\7z.exe" a -tzip -mx9 ..\ -r 
rd library /s /q 
"C:\devel\upx201w\upx.exe" --best *.* 

I'm assuming that you have 7-Zip ( and UPX ( installed. Change the paths in the batch file to the corresponding paths on your computer. Using 7-Zip's superior compression and UPX's executable size reduction, I managed to strip my 10.5 megabyte application down to 4.5 megabytes.

Creating the Installer

I use NSIS ( to generate my installers, but you don't have to. The other major installer generator is Inno Setup ( Combined with NSIS, I use HM NIS Edit ( to generate my scripts from a plug-in. Both of these installer tools further compress your application - use LZMA compression, as it generally works the best.

You are intelligent if you got this far, so I'll leave learning how to use these excellent installer tools to you.

DistributingYourApplication (last edited 2008-03-11 10:50:29 by localhost)