The “Build Applet.app,” which comes with the Python developer tools, is actually a pure Python application package. It performs the following actions:
- the Python interpreter is placed (or bound) into the
MacOS/ directory - the executable script file (
Foo.app/Contents/MacOS/Foo ) sets some environment variables for this interpreter and calls os.execve() .
The executable script looks like this (assuming the program entry point is in Resources/main.py ):
#!/System/Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python import sys, os execdir = os.path.dirname(sys.argv[0]) executable = os.path.join(execdir, "Python") resdir = os.path.join(os.path.dirname(execdir), "Resources") libdir = os.path.join(os.path.dirname(execdir), "Frameworks") mainprogram = os.path.join(resdir, "main.py") sys.argv.insert(1, mainprogram) pypath = os.getenv("PYTHONPATH", "") if pypath: pypath = ":" + pypath os.environ["PYTHONPATH"] = resdir + pypath os.environ["PYTHONEXECUTABLE"] = executable os.environ["DYLD_LIBRARY_PATH"] = libdir os.environ["DYLD_FRAMEWORK_PATH"] = libdir os.execve(executable, sys.argv, os.environ)
source share