[issue38905] venv python reports wrong sys.executable in a subprocess on Windows

Steve Dower report at bugs.python.org
Tue Nov 26 12:31:37 EST 2019


Steve Dower <steve.dower at python.org> added the comment:

> But then I need two separate workflows based on what is passed in. For py.exe I need to run it and get sys.executable. But for python.exe I *cannot* use sys.executable because that’s the base interepeter, not the venv path I want. And `if Path(arg).stem == "py"` just seems like a bug waiting to happen.

If you use shutil.which() to resolve "python" or "py" against PATH (which doesn't include the application directory), then you'll get the full path to the correct python.exe and will get the expected sys.executable. So it's only one flow that works for both once you add the shutil.which step.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38905>
_______________________________________


More information about the Python-bugs-list mailing list