4

I want to make a Python script - let's call it exe.py - which basically behaves exactly like the Python executable (python.exe, /usr/bin/python, etc.) does. That is:

  • python exe.py runs a shell
  • python exe.py script.py runs the Python script
  • python exe.py script.py a b c runs the Python script with args
  • python exe.py -c ... runs a command
  • python exe.py -m ... runs a module
  • python exe.py -h prints that help screen
  • etc...

I could of course re-implement all this, but I wonder if there isn't a programmatic way to simply pass through the command line and all the arguments and have it behave exactly like python.exe does? Much in the same way as it's possible to run an interactive shell without re-implementing the entire interactive shell.

XY PROBLEM: What I'm actually doing is creating a stand-alone executable with certain hard-to-install libraries packaged into it. I'd like to provide a way to run the version of Python being bundled into the stand-alone executable. PyInstaller takes Python scripts as entry points and turns them into executables for whatever target platform it's building for, so I want to make a Python script which just behaves exactly like the python executable does, so it can be turned into a stand-alone and run in the environment of the packaged executable.

As such I can't just invoke the Python executable since that won't be the packaged version's executable.

Claudiu
  • 224,032
  • 165
  • 485
  • 680
  • You could pass along `sys.args` to the real python executable. But why? If your program doesn't do anything except what python already does, why create it? – BrenBarn Nov 28 '16 at 19:39
  • @BrenBarn: Ah yeah I just updated the question, see the "XY PROBLEM" section – Claudiu Nov 28 '16 at 19:40
  • By scripts you mean as in bash/sh/whatever scripts? – kabanus Nov 28 '16 at 19:47
  • @kabanus: So PyInstaller takes Python scripts as entrypoints, and it turns them into executables (~3.3 MB each on mac) for whatever platform it's deploying for – Claudiu Nov 28 '16 at 19:49
  • Yes, but is your final goal is an executable, or a python script?. Edit your question so that's clear. – kabanus Nov 28 '16 at 19:50

0 Answers0