== Introduction == This page will provide a basic setup.py for Python 2.6 for a simple wxPython based script (e.g. the one shown on the previous page). * you will need the version 9 MS C run time dll included with Python * the dll 'gdiplus.dll' might also be needed depending on what wxPython widgets you use == Notes to the setup.py == I use GUI2Exe to create the inital version of my setup.py, I then export them and maintain them with 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 reduce this further by including 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. In the dll_excludes option the following dll's "'mswsock.dll', 'powrprof.dll', 'uxTheme.dll'" are listed to force py2exe to ignore them. Should they be included you would get problems on systems other then the one you frooze your application on. In the dll_excludes option you also need to add "'MSVCP90.dll'," as otherwise py2exe will throw an exception when you try to freeze the application. == 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. It is a bit different then for Python 2.5 and earlier as there is an additional section in it for the MS C Run time version 9 stuff (sometimes refered to as SxS (Side by Side), the files needed for this are MSVCR90.dll and some application might also need MSVCP90.dll, they are included with your Python 2.6 installation (either in your Python 2.6 folder if you installed "for you only", otherwise they are in the "SxS" folder "C:\Windows\winsxs" on most systems), they are also in the Visual Studio redistribution folder or they can be obtained from the Microsoft web site. I keep them in a folder "Py26MSdlls-9.0.21022.8" and include them from there, which is shown in the following. == 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. \python26\python setup.py py2exe With py2exe version 0.6.9 you will see a deprecation warning for the "sets" module, which you can savely ignore. {{{ #!python # ======================================================# # File automagically generated by GUI2Exe version 0.3 # Andrea Gavana, 01 April 2007 # ======================================================# # Let's start with some default (for me) imports... from distutils.core import setup import py2exe import glob import os import zlib import shutil # Remove the build folder shutil.rmtree("build", ignore_errors=True) # do the same for dist folder shutil.rmtree("dist", ignore_errors=True) MANIFEST_TEMPLATE = """ <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <assemblyIdentity version="5.0.0.0" processorArchitecture="x86" name="%(prog)s" type="win32" /> <description>%(prog)s</description> <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> <security> <requestedPrivileges> <requestedExecutionLevel level="asInvoker" uiAccess="false"> </requestedExecutionLevel> </requestedPrivileges> </security> </trustInfo> <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"> </assemblyIdentity> </dependentAssembly> </dependency> <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*" /> </dependentAssembly> </dependency> </assembly> """ class Target(object): """ A simple class that holds information on our executable file. """ def __init__(self, **kw): """ Default class constructor. Update as you need. """ self.__dict__.update(kw) # Ok, let's explain why I am doing that. # Often, data_files, excludes and dll_excludes (but also resources) # can be very long list of things, and this will clutter too much # the setup call at the end of this file. So, I put all the big lists # here and I wrap them using the textwrap module. data_files = [] includes = [] excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger', 'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl', 'Tkconstants', 'Tkinter'] packages = [] dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll', 'tk84.dll', 'MSVCP90.dll', 'mswsock.dll', 'powrprof.dll'] icon_resources = [] bitmap_resources = [] other_resources = [] other_resources = [(24, 1, MANIFEST_TEMPLATE % dict(prog="MyAppName"))] # This is a place where the user custom code may go. You can do almost # whatever you want, even modify the data_files, includes and friends # here as long as they have the same variable name that the setup call # below is expecting. # # The following will copy the MSVC run time dll's # (msvcm90.dll, msvcp90.dll and msvcr90.dll) and # the Microsoft.VC90.CRT.manifest which I keep in the # "Py26MSdlls" folder to the dist folder # # depending on wx widgets you use, you might need to add # gdiplus.dll to the above collection py26MSdll = glob.glob(r"c:\Dev\Py26MSdlls-9.0.21022.8\msvc\*.*") # install the MSVC 9 runtime dll's into the application folder data_files += [("", py26MSdll),] # I found on some systems one has to put them into sub-folders. ##data_files += [("Microsoft.VC90.CRT", py26MSdll), ## ("lib\Microsoft.VC90.CRT", py26MSdll)] # Ok, now we are going to build our target class. # I chose this building strategy as it works perfectly for me :-D GUI2Exe_Target_1 = Target( # what to build script = "simplewx.py", icon_resources = icon_resources, bitmap_resources = bitmap_resources, other_resources = other_resources, dest_base = "simplewx", version = "0.1", company_name = "No Company", copyright = "No Copyrights", name = "Py2Exe Sample File" ) # That's serious now: we have all (or almost all) the options py2exe # supports. I put them all even if some of them are usually defaulted # and not used. Some of them I didn't even know about. setup( data_files = data_files, options = {"py2exe": {"compressed": 2, "optimize": 2, "includes": includes, "excludes": excludes, "packages": packages, "dll_excludes": dll_excludes, "bundle_files": 2, "dist_dir": "dist", "xref": False, "skip_archive": False, "ascii": False, "custom_boot_script": '', } }, zipfile = "lib\library.zip", console = [], windows = [GUI2Exe_Target_1] ) # This is a place where any post-compile code may go. # You can add as much code as you want, which can be used, for example, # to clean up your folders or to do some particular post-compilation # actions. # 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.