Bug report
Bug description:
On Linux, sys.executable is determined using argv[0], and trying to find that in the PATH. This presumes that the Python interpreter has been started by a shell that interprets PATH in the canonical way. There is no guarantee that this happens at all, so sys.executable may point to something completely different, or is even the empty string.
As an example:
bash -c 'exec -a whatever python -c "import sys;print(sys.executable)"'
should output the path of the Python executable, but simply outputs nothing.
Even worse, one can make Python output a wrong executable, as in
bash -c 'exec -a /usr/bin/python python -c "import sys;print(sys.executable)"'
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
Bug report
Bug description:
On Linux,
sys.executableis determined usingargv[0], and trying to find that in thePATH. This presumes that the Python interpreter has been started by a shell that interpretsPATHin the canonical way. There is no guarantee that this happens at all, sosys.executablemay point to something completely different, or is even the empty string.As an example:
should output the path of the Python executable, but simply outputs nothing.
Even worse, one can make Python output a wrong executable, as in
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
/proc/self/exeto determinesys.executable#145486