Python Forum
Why is PYTHONEXECUTABLE only supported on MAC OS X?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why is PYTHONEXECUTABLE only supported on MAC OS X?
#4
I'm unable to answer the title of this thread, that is a question for the Python core dev team, but you could try the following workaround:

instead of execve-ing python with the arguments that you showed above, you would execve python wrapper2.py <any args you want>. Then wrapper2.py would do something like

# wrapper2.py
import importlib.util
import sys
modname = ... # should extract 'blurble.libexec.util_one' from sys.argv
spec = importlib.util.find_spec(modname)
assert(spec.origin.endswith('.py'))  # should be '/path/to/blurble/libexec/util_one.py'
with open(spec.origin) as ifh:
    code = compile(ifh.read(), spec.origin, 'exec')
sys.argv[:] = ... # do anything you want with sys.argv
mainmod = sys.modules['__main__']
mainmod.__file__ = spec.origin
exec(code, mainmod.__dict__)  # run the desired program in the __main__ module.
Of course, you would hide all this in a function's body (or an external module) to avoid cluttering the __main__ module's namespace.
Reply


Messages In This Thread
RE: Why is PYTHONEXECUTABLE only supported on MAC OS X? - by Gribouillis - Nov-16-2021, 09:04 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020