Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
Open
Description
Bug report
Bug description:
On Linux, executables from the cwd are used whenPATH is unset:
$PATH= python -VPython 3.13.7
subprocess.run also works in this case:
$PATH= python -q>>> from subprocess import run... run(['python', '-V'])...Python 3.13.7CompletedProcess(args=['python', '-V'], returncode=0)>>>
Butshutil.which returnsNone:
>>>fromshutilimportwhich>>>which('python')>>>
This is because whenPATH is empty(""), the executable ("python") is passed to the kernel'sexecve directly, without resolving.execve then resolves the file relative to the cwd, I believe it's the case in bothLinux andFreeBSD.
POSIX 2024 says this about the PATH environment variable:
If PATH is unset or is set to null, or if a path prefix in PATH contains a character ('%'), the path search is implementation-defined.
EDIT: PATH is empty, not unset
CPython versions tested on:
3.13
Operating systems tested on:
Linux