Skip to content

Instantly share code, notes, and snippets.

@heetbeet
Created May 2, 2020 12:47
Show Gist options
  • Save heetbeet/b6dd0f64b262c388a652483c155f632a to your computer and use it in GitHub Desktop.
Save heetbeet/b6dd0f64b262c388a652483c155f632a to your computer and use it in GitHub Desktop.
Compile this file to get a mini python.exe with auto-py-to-exe
'''
This script mimicks part of the python executable, in order for it to be
compiled and shipped using auto-py-to-exe
'''
import sys
import os
thisdir = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(thisdir, 'site-packages'))
sys.path.insert(0, os.path.join(thisdir))
if sys.argv[1] == "--help" or sys.argv[1] == "-h":
print('''usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Options and arguments (and corresponding environment variables):
-c cmd : program passed in as string (terminates option list)
-h : print this help message and exit (also --help)
-V : print the Python version number and exit (also --version)''')
if sys.argv[1] == "--version" or sys.argv[1] == "-V":
print("Python "+('.'.join(str(i) for i in sys.version_info[:3])))
elif sys.argv[1] == "-c":
exec(sys.argv[2])
else:
__file__ = os.path.abspath(sys.argv[1])
sys.argv = sys.argv[1:]
exec(open(__file__).read())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment