bootstrap script for idle as an application bundle change the current directory the user s home directory that way we ll get a more useful default location in the opensave dialogs make sure sys executable points to the python interpreter inside the framework instead of at the helper executable inside the application bundle the latter works but doesn t allow access to the window server idle app contents macos idle a python script python32 symlink resources idlemain py this module idle appcontentsmacospython32 is symlinked to libraryframeworkspython frameworkversionsm n resourcespython appcontentsmacospython32 which is the python interpreter executable the flow of control is as follows 1 idle app is launched which starts python running the idle script 2 idle script exports pythonexecutable idle appcontentsmacospython32 the symlink to the framework python 3 idle script alters sys argv and uses os execve to replace itself with idlemain py running under the symlinked python this is the magic step 4 during interpreter initialization because pythonexecutable is defined sys executable may get set to an useless value note that the idle script and the setting of pythonexecutable is generated automatically by bundlebuilder in the python 2 x build also idle invoked via command line i e binidle bypasses all of this now fix up the execution environment before importing idlelib reset sys executable to its normal value the actual path of the interpreter in the framework by following the symlink exported in pythonexecutable remove any sys path entries for the resources dir in the idle app bundle unexport pythonexecutable so that the other python processes started by idle have a normal sys executable look for the psn argument that the launcher adds and remove it it will only confuse the idle startup code now it is safe to import idlelib change the current directory the user s home directory that way we ll get a more useful default location in the open save dialogs make sure sys executable points to the python interpreter inside the framework instead of at the helper executable inside the application bundle the latter works but doesn t allow access to the window server idle app contents macos idle a python script python 32 symlink resources idlemain py this module idle app contents macos python 32 is symlinked to library frameworks python framework versions m n resources python app contents macos python 32 which is the python interpreter executable the flow of control is as follows 1 idle app is launched which starts python running the idle script 2 idle script exports pythonexecutable idle app contents macos python 32 the symlink to the framework python 3 idle script alters sys argv and uses os execve to replace itself with idlemain py running under the symlinked python this is the magic step 4 during interpreter initialization because pythonexecutable is defined sys executable may get set to an useless value note that the idle script and the setting of pythonexecutable is generated automatically by bundlebuilder in the python 2 x build also idle invoked via command line i e bin idle bypasses all of this now fix up the execution environment before importing idlelib reset sys executable to its normal value the actual path of the interpreter in the framework by following the symlink exported in pythonexecutable remove any sys path entries for the resources dir in the idle app bundle unexport pythonexecutable so that the other python processes started by idle have a normal sys executable look for the psn argument that the launcher adds and remove it it will only confuse the idle startup code now it is safe to import idlelib
import sys, os



os.chdir(os.path.expanduser('~/Documents'))









































pyex = os.environ['PYTHONEXECUTABLE']
sys.executable = os.path.join(sys.prefix, 'bin', 'python%d.%d'%(sys.version_info[:2]))


p = pyex.partition('.app')
if p[2].startswith('/Contents/MacOS/Python'):
    sys.path = [value for value in sys.path if
            value.partition('.app') != (p[0], p[1], '/Contents/Resources')]



del os.environ['PYTHONEXECUTABLE']



for idx, value in enumerate(sys.argv):
    if value.startswith('-psn_'):
        del sys.argv[idx]
        break


from idlelib.pyshell import main
if __name__ == '__main__':
    main()