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.

5
  • 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? Commented Nov 28, 2016 at 19:39
  • @BrenBarn: Ah yeah I just updated the question, see the "XY PROBLEM" section Commented Nov 28, 2016 at 19:40
  • By scripts you mean as in bash/sh/whatever scripts? Commented Nov 28, 2016 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 Commented Nov 28, 2016 at 19:49
  • Yes, but is your final goal is an executable, or a python script?. Edit your question so that's clear. Commented Nov 28, 2016 at 19:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.