コード例 #1
0
import sys
import runpy

if sys.executable.endswith("thonny.exe"):
    # otherwise some library may try to run its subprocess with thonny.exe
    sys.executable = sys.executable[:-len("thonny.exe")] + "pythonw.exe"

from thonny import launch

try:
    runpy.run_module("thonny.customize", run_name="__main__")
except ImportError:
    pass

launch()
コード例 #2
0
# Reset sys.executable to its normal value, the actual path of
# the interpreter in the framework, by following the symlink
# exported in PYTHONEXECUTABLE.
pyex = os.environ['PYTHON_SYS_EXECUTABLE']
sys.executable = os.path.join(sys.prefix, 'bin',
                              'python%d.%d' % (sys.version_info[:2]))

# Remove any sys.path entries for the Resources dir in the Thonny.app bundle.
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')
    ]

# Unexport PYTHONEXECUTABLE so that the other Python processes started
# by Thonny have a normal sys.executable.
del os.environ['PYTHON_SYS_EXECUTABLE']

# Look for the -psn argument that the launcher adds and remove it, it will
# only confuse the Thonny startup code.
for idx, value in enumerate(sys.argv):
    if value.startswith('-psn_'):
        del sys.argv[idx]
        break

# Now it is safe to import thonny.
if __name__ == '__main__':
    import thonny
    thonny.launch()