Introduction

This page will provide a basic setup.py for Python 2.5 for a simple wxPython based script (e.g. the one shown on the previous page).

Notes to the setup.py

I use GUI2Exe to create the inital version of my setup.py, I then export them and maintain them in my standard IDE.

If you want to reduce the number of files in your "dist" folder then it is recommended to use the "bundle=3" and the "zipfile = "lib/library.zip" options. "bundle=2" will include more of the files in the library.zip, however it might cause problems with more complex applications, "bundle=1" is not recommended as it causes to often problems.

Notes to the manifest

The manifest included in the following setup.py ensures that your application has a "nicer" look, by forcing the application to use version 6 of the Microsoft common controls.

freezing your application

To "freeze" the application you run the following command from the command line in your working folder, or use the appropriate option in your IDE.

\python25\python setup.py py2exe

   1 # ======================================================#
   2 # File automagically generated by GUI2Exe version 0.3
   3 # Andrea Gavana, 01 April 2007
   4 # ======================================================#
   5 
   6 # Let's start with some default (for me) imports...
   7 
   8 from distutils.core import setup
   9 import py2exe
  10 import glob
  11 import os
  12 import zlib
  13 import shutil
  14 
  15 # Remove the build folder
  16 shutil.rmtree("build", ignore_errors=True)
  17 
  18 # do the same for dist folder
  19 shutil.rmtree("dist", ignore_errors=True)
  20 
  21 MANIFEST_TEMPLATE = """
  22 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  23 <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  24   <assemblyIdentity
  25     version="5.0.0.0"
  26     processorArchitecture="x86"
  27     name="%(prog)s"
  28     type="win32"
  29   />
  30   <description>%(prog)s</description>
  31   <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
  32     <security>
  33       <requestedPrivileges>
  34         <requestedExecutionLevel
  35             level="asInvoker"
  36             uiAccess="false">
  37         </requestedExecutionLevel>
  38       </requestedPrivileges>
  39     </security>
  40   </trustInfo>
  41   <dependency>
  42     <dependentAssembly>
  43         <assemblyIdentity
  44             type="win32"
  45             name="Microsoft.Windows.Common-Controls"
  46             version="6.0.0.0"
  47             processorArchitecture="X86"
  48             publicKeyToken="6595b64144ccf1df"
  49             language="*"
  50         />
  51     </dependentAssembly>
  52   </dependency>
  53 </assembly>
  54 """
  55 
  56 class Target(object):
  57     """ A simple class that holds information on our executable file. """
  58     def __init__(self, **kw):
  59         """ Default class constructor. Update as you need. """
  60         self.__dict__.update(kw)
  61         
  62         
  63 # Ok, let's explain why I am doing that.
  64 # Often, data_files, excludes and dll_excludes (but also resources)
  65 # can be very long list of things, and this will clutter too much
  66 # the setup call at the end of this file. So, I put all the big lists
  67 # here and I wrap them using the textwrap module.
  68 
  69 data_files = []
  70 
  71 includes = []
  72 # excludes some stuff which is not needed with wxPython
  73 excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger',
  74             'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl',
  75             'Tkconstants', 'Tkinter']
  76 packages = []
  77 dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll',
  78                 'tk84.dll']
  79 icon_resources = []
  80 bitmap_resources = []
  81 other_resources = []
  82 other_resources = [(24, 1, MANIFEST_TEMPLATE % dict(prog="MyAppName"))]
  83 
  84 
  85 # This is a place where the user custom code may go. You can do almost
  86 # whatever you want, even modify the data_files, includes and friends
  87 # here as long as they have the same variable name that the setup call
  88 # below is expecting.
  89 
  90 
  91 # Ok, now we are going to build our target class.
  92 # I chose this building strategy as it works perfectly for me :-D
  93 
  94 
  95 GUI2Exe_Target_1 = Target(
  96     # what to build
  97     script = "simplewx.py",
  98     icon_resources = icon_resources,
  99     bitmap_resources = bitmap_resources,
 100     other_resources = other_resources,
 101     dest_base = "simplewx",    
 102     version = "0.1",
 103     company_name = "No Company",
 104     copyright = "No Copyrights",
 105     name = "Py2Exe Sample File"
 106     )
 107 
 108 
 109 
 110 # That's serious now: we have all (or almost all) the options py2exe
 111 # supports. I put them all even if some of them are usually defaulted
 112 # and not used. Some of them I didn't even know about.
 113 
 114 setup(
 115 
 116     data_files = data_files,
 117 
 118     options = {"py2exe": {"compressed": 2, 
 119                           "optimize": 2,
 120                           "includes": includes,
 121                           "excludes": excludes,
 122                           "packages": packages,
 123                           "dll_excludes": dll_excludes,
 124                           "bundle_files": 2, # or 3 but do not use 1 it often causes problems
 125                           "dist_dir": "dist",
 126                           "xref": False,
 127                           "skip_archive": False,
 128                           "ascii": False,
 129                           "custom_boot_script": '',
 130                          }
 131               },
 132 
 133     zipfile = "lib\library.zip",
 134     console = [],
 135     windows = [GUI2Exe_Target_1]
 136     )
 137 
 138 # This is a place where any post-compile code may go.
 139 # You can add as much code as you want, which can be used, for example,
 140 # to clean up your folders or to do some particular post-compilation
 141 # actions.
 142 
 143 # And we are done. That's a setup script :-D

Additional notes by users

Please use this section to add a note about your experience with py2exe and wxPython.

py2exe-python25 (last edited 2010-08-08 15:49:45 by 113)