Okay i have created a wxPython application and converted it into an windows executable programme using py2exe. The app works perfectly but every time i run the exe the console window appears with the gui. Is there anyway to get rid of the console because the app has to run on other workstations.

Usually you can give your Python code a .pyw extension. This will use the pythonw.exe interpreter avoiding the DOS console.

If you create a distribution with py2exe then you have to make sure you specify windows in the setup ...

"""
file = wx2exe.py

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

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

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

Two subfolders will be created called build and dist.
The build folder is for info only and can be deleted.
Distribute whatever is in the dist folder.
The dist folder contains your .exe file, MSVCR71.dll and w9xpopen.exe
Your .exe file contains your code, all needed modules and the Python
interpreter (as a Pythonxx.dll).
MSVCR71.dll can be distributed, but is often already in the 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.6"
        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 version info resource
# script is the wxPython code file name
# 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}},
    zipfile = None,
    # to add .dll or image files use list of filenames
    # this files are added to the dir containing the exe file
    #data_files = ['BG_psychedelic.gif', 'Notes1.jpg'],
    windows = [test_wx]
    )

wow thanks alot vegaseat

Look at Gui2exe to.
Dos not create console default.

in wxApp you should disable it

myApp = wx.App(False)

in wxApp you should disable it

myApp = wx.App(False)

That only affects the error log and console output ...

# redirect=False sends error and print messages to the console window
# redirect=True sends error and print messages to a wx popup window 
app = wx.App(redirect=True)

That only affects the error log and console output ...

# redirect=False sends error and print messages to the console window
# redirect=True sends error and print messages to a wx popup window 
app = wx.App(redirect=True)

I misunderstood the question :'(

Hi Vega, okay i used your py2exe template and converted my app to an windows app. when i tried to run the app i got the missing dll error message(MSVCR90.dll). so downloaded the dll and copied it into the system32 folder but now i get another error that reads "The application failed to initialize properly (0xc0000142)". any help will be greatly appreciated.

Yeah, i got that. Its easily fixed by taking out the manifest. I didn't have this problem with windows XP but i am getting it with 7.
So i would use gui2exe like suggested above and just make sure that XP manifest file is unticket down the bottom

Hope that helps :)

I'll try that but when using gui2exe i got compile errors which i can't remember.

okay i took your advice paul and it works beautifully another question though; i have included an icon for the app and on my pc it's there but on someone else's pc it's not (has the default icon). any advice.

Perhaps just put it in the same directory as your executable. That could help, i have never really used icons on my programs so i'm not super sure, but when i use files in my executables such as .txt and .jpg i need to make sure that they are either bundled into the program (a bit of work) or in the same directory as the exe.


Hope that helps :)

ooh 999 posts, cant wait for the next one

Hi Vega, okay i used your py2exe template and converted my app to an windows app. when i tried to run the app i got the missing dll error message(MSVCR90.dll). so downloaded the dll and copied it into the system32 folder

I would rather copy it in same folder with app than clogging my System folders, But again that is my behaviour ;)

I would rather copy it in same folder with app than clogging my System folders, But again that is my behaviour ;)

That was the first thing i did :)

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.