Introduction

On Mac OS X, both 'python' and 'pythonw' exist as commands, but 'pythonw' needs to be called for any wxPython app run from the command line.

Solution

The code sample below when called from a main script checks whether the script is running from within a Mac OS X app bundle. If not, it re-rexecutes the same script with the same arguments using pythonw.

It's simple, but useful for distributing cross-platform apps that can be run from the command line.

Code Sample

import sys,os

def reexec_with_pythonw():
    if sys.platform == 'darwin' and\
           not sys.executable.endswith('MacOS/Python'):
        print >>sys.stderr,'re-executing using pythonw'
        os.execvp('pythonw',['pythonw',__file__] + sys.argv[1:])

Comments

Corrections/Suggestions welcome.

Automatically Calling pythonw on Mac OS X (last edited 2008-03-11 10:50:22 by localhost)

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