-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
distutils: find_executable() fails if the PATH environment variable is not set #78711
Comments
Example: $ env -i ./python -c 'import distutils.spawn; print(distutils.spawn.find_executable("true"))'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/vstinner/prog/python/master/Lib/distutils/spawn.py", line 176, in find_executable
path = os.environ['PATH']
File "/home/vstinner/prog/python/master/Lib/os.py", line 672, in __getitem__
raise KeyError(key) from None
KeyError: 'PATH' Attached PR fixes the issue for the master branch. |
I'm not sure that it's worth it to modify Python 3.7 and older. distutils changes are now well welcomed (breaking setuptools or pip is unpopular :-)). |
find_executable() always searches executables from the current directory. This effectively equivalent having os.curdir at the start of path. shutil.which() does this only on Windows. This change LGTM, but it potentially can break user code, thus it may be not safe to make it in maintained versions. |
Oh! I didn't notice that! |
I missed the fact that find_executable() always lookup in the current directory, whereas shutil.which() doesn't. I abandoned my PR 8968 in favor of PR 9049 which only fix the case where PATH env var is not defined. This PR can easily be backported to all branches, whereas backporting PR 8968 to stable branches would be risky: changes to distutils are likely to break a random package on PyPI. |
I chose to merge the simplest change:
+ path = os.environ.get('PATH', os.defpath) And I added unit tests for find_executable(). The bug is now fixed. I'm not longer interested to reuse shutil.which() in distutils.find_executable(), since find_executable() first checks if the executable is in the current directory. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: