Has anybody ever used py2exe and wxPython together? I have no idea what i'm doing (as usual) and would appreciate it if anyone could walk me through the process or point me to a tutorial online. All the tutorials I've seen (which isn't many) don't make much sense to me.

I want to make my wxPython program into a .exe. Any help is much appreciated!

Recommended Answers

All 13 Replies

http://code.google.com/p/gui2exe/
Start with python <your path> GUI2Exe.py choose your wxpython script.
Set Optimize 2 | Compressed 3 | Bundle Files 3
Complie-->finish test your program.

You can run this Python file after proper option modifications to package a wxPython program with py2exe ...

"""
file = wx2exeZ.py

Py2Exe (version 6.6 and higher) setup file for wxPython GUI programs.
Creates an exe file and a library.zip file.

It's easiest to save this wx2exeZ.py file into the same folder
folder with the source file and needed image files.

Give your correct source file name and run wx2exeZ.py ...

Two subfolders are created called dist and build.
The build folder is temporary and for info and can be deleted.
Distribute whatever is in the dist folder.
The dist folder contains your .exe file, library.zip, MSVCR71.dll
and w9xpopen.exe

Your library.zip file contains your optimized byte code, all needed
modules, the Python interpreter (eg. Python25.dll).  Note that with
Python/wxPython programs you might be able to share the large zip
library file with other similar exe files.

MSVCR71.dll can be distributed and is often already in the
Windows/system32 folder.  Python26+ uses a higher version MSVCR90.dll
w9xpopen.exe is needed for os.popen() only, can be deleted otherwise.
"""

from distutils.core import setup
import py2exe
import sys

# important >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# enter the filename of your wxPython code file to compile
filename = "wxButton1.py"

# this creates the filename of your .exe file in the dist folder
if filename.endswith(".py"):
    distribution = filename[:-3]
elif filename.endswith(".pyw"):
    distribution = filename[:-4]

# if run without args, build executables in quiet mode
if len(sys.argv) == 1:
    sys.argv.append("py2exe")
    sys.argv.append("-q")

class Target:
    """ edit the version/name info as needed """
    def __init__(self, **kw):
        self.__dict__.update(kw)
        # for the versioninfo resources, edit to your needs
        self.version = "0.6.3"
        self.company_name = "My Company"
        self.copyright = "no copyright"
        # fill this in with your own program description
        self.name = "WxPython Button Test"

# start of manifest for custom icon and appearance ...
#
# This XML manifest will be inserted as resource into your .exe file
# It gives the controls a Windows XP appearance (if run on XP)
#
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 Program</description>
<dependency>
    <dependentAssembly>
        <assemblyIdentity
            type="win32"
            name="Microsoft.Windows.Common-Controls"
            version="6.0.0.0"
            processorArchitecture="X86"
            publicKeyToken="6595b64144ccf1df"
            language="*"
        />
    </dependentAssembly>
</dependency>
</assembly>
'''

RT_MANIFEST = 24

# description is the versioninfo resource
# script is the wxPython code file
# manifest_template is the above XML code
# distribution will be the exe filename
# icon_resource is optional, remove any comment and give it
# an iconfile you have, otherwise a default icon is used
# dest_base will be the exe filename
test_wx = Target(
    description = "A GUI app",
    script = filename,
    other_resources = [(RT_MANIFEST, 1, \
        manifest_template % dict(prog=distribution))],
    # remove comment below if you want to use your own icon
    #icon_resources = [(1, "icon.ico")],
    dest_base = distribution)

# end of manifest

setup(
    options = {"py2exe": {"compressed": 1,
                          "optimize": 2,
                          "ascii": 1,
                          "bundle_files": 1}},
    # remove comment below to put all data into single exe file
    #zipfile = None,
    # to add .dll or image files use list of filnames
    # these files are added to the dir containing the exe file
    #data_files = ['./images/red.jpg', './images/'blue.jpg'],
    windows = [test_wx]
)

One option is to produce a single .exe file or a .exe file with a .zip library file. Read the comments. I use this program for all my wxPython distributions.

How about compiling it to be a background process. Like .pyw?
I tried compiling .pyw's but it still shows the console box.

Never mind lol. I found it.

setup(windows=["file.py"])

Use GUI2exe. It have many options on GUI. You can optionally generate setup.py and edit manually to suit your case

Vegas, I just tried using your code and I had some trouble. I got an error that said:

Traceback (most recent call last):
  File "C:/Users/Alexander/Desktop/New Folder/wx2exeZ.py", line 118, in <module>
    windows = [test_wx]
  File "C:\Python26\lib\distutils\core.py", line 162, in setup
    raise SystemExit, error
SystemExit: error: MSVCP90.dll: No such file or directory

Do you know what the problem is and what I need to do to fix it? I don't know anything about .dll files.

Ok, so I think i've filled it out...

#for no console: windows = ["file.py"],
#for console: console = ["file.py"],
#default icon setup
#for custom icons : console = [{"script": "file.py", "icon_resources": [(0, "icon.ico")]}]

from distutils.core import setup
import py2exe
from glob import glob

 
data_files = [("Microsoft.VC90.CRT",
               glob('C:\\Users\\Alexander\\Desktop\\New Folder\\BuildEnvio\\Microsoft.VC90.CRT'))] #change to the path
setup(
      data_files=data_files,
      version="1.0",
      description = "Ping Pong Stats",
      name = "Donkey Pong",
      windows = [{"script": "donkeypong.py",
      options = {'py2exe':{'bundle_files':1}},
      )

...but it says I have a syntax error and highlights the = after options. What should I do?

Ok, update on the problem. I got the DLL's i needed and put them in the Python DLL folder. However when I use the program (from Vegas) it says:

Your executable(s) also depend on these dlls which are not included,
you may or may not need to distribute them.

So, how do I distribute the DLL's?

That means that the persons you distribute it to may not have the required DLL's.
I wrote a backdoor and it worked on my wife's laptop and the schools systems, but not my mother-in-laws system because she doesn't have the required DLL's.
Some DLL's are copyrighted and do not allow distribution. Some are not. You will have to read the documentation for them to see if they are or are not.

Post your script so can i test i out.

Hmmm, I used the GUI2exe and it was less complicated but I keep getting the same error with my program. When I try to open it it says:

Runtime Error!

Program: C:\Users\Alexander\Desktop\New
Folder\dist\DonkeyPong.exe

R6034
An application has made an attempt to load the C runtime library
incorrectly.
Please contact the application's support team for more information.

Also, when following the compiler messages in GUI2exe, I see this:

C:\Python26\lib\site-packages\py2exe\build_exe.py:16: DeprecationWarning: the sets module is deprecated

Did all this py2exe stuff just work for you guys when you tried it? I don't get why I am having so many errors. Anyone know what's wrong?

Post 2# my setup in gui2exe.
I have done a lot with wxpython and py2exe(gui2exe + inno-setup)
And it works on all windows version,no need for pepole to have python installed.

Is better that you post your script so can we test it out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.