Intro

This page is intended to be a detailed guide to bundling wxPython applications with py2exe with Python 2.6. The main py2exe page in the wiki has some incomplete and incorrect information about using py2exe with Python2.6. Hopefully when I have some more time I can merge this information into that page but making a new page was faster than doing that for now so here we go.

Getting Started

The Python2.6 binaries are built with a newer version of the Windows C runtimes than 2.5. These newer runtimes bring us out of DLL hell and into SxS assembly hell ;)

Its not that bad though so assuming that you have already installed Python2.6 and py2exe you will need to have two more files on hand to build your application.

Setup.py

There are a few changes that need to be made to your setup.py file in comparison to builds using Python 2.5. First the embedded manifest is different and a small tweak to the dll_excludes is necessary to get rid of an error that can occur when running py2exe.

Manifest Template

The following manifest can be used to create exe's that will use the correct themed controls on both Windows XP and Vista/Windows 7.

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>
"""

The main difference with this manifest and previous incarnations is the added dependency on Microsoft.VC90.CRT.

Py2exe Options

The following is an example set of py2exe options to pass to the setup() function.

There are two things to take note of here.

setup(name = "MyApp",
      version = "1.0",
      options = {"py2exe" : {"compressed" : 1,
                             "optimize" : 2,
                             "bundle_files" : 2,
                             "includes" : INCLUDES,
                             "excludes" : ["Tkinter",],
                             "dll_excludes": [ "MSVCP90.dll" ] }},
      windows = [{"script": "src/Editra.py",
                  "icon_resources": [(1, "myapp.ico")],
                  "other_resources" : [(RT_MANIFEST, 1,
                                        MANIFEST_TEMPLATE % dict(prog="MyAppName"))],
                  }],
      description = "Description of the app",
      author = "Author Name",
      author_email ="author@project.com",
      maintainer = "Maintainer Name",
      maintainer_email = "you@project.com",
      license = "wxWindows Licence",
      url = "http://projecthomepage.com",
      data_files = ["MSVCR90.dll", "gdiplus.dll"],
      )

Conclusions

All that is left to be able to run your built application is to include the two DLL's from earlier in the dist directory that was output by running setup.py py2exe.

TODO

Some things seem to have changed with embedding icons into the exe. Explorer does not always show the applications icon in Windows Vista/7. Mostly noticeable when looking at the exe file, shortcuts to it, and the taskbar when the app is running. Need to investigate if file format changed or if further manifest tweaks are necessary.

Py2exe with Python2.6 (last edited 2010-07-19 18:42:03 by 74)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.