[issue41965] distutils.spawn.find_executable() fails to find .py files on Windows

Eryk Sun report at bugs.python.org
Wed Oct 7 09:12:06 EDT 2020


Eryk Sun <eryksun at gmail.com> added the comment:

The existing behavior of find_executable() is unusual compared to a native Windows file search via CreateProcessW or SearchPathW, for which a default ".exe" extension is appended only if the executable name doesn't already have an extension. (CreateProcessW supports searching for a file that has no extension by adding a trailing dot to the name, which in Windows is equivalent to the name without the trailing dot.) 

However, I don't think it's prudent to change the default behavior of this old code, especially since there are plans to deprecate distutils per PEP 632. It's recommended to migrate existing code to use shutil.which() and subprocess.run(). 

There are open issues to improve the behavior of shutil.which() in Windows. For example, currently it's limited to PATHEXT extensions, which is a generalization of how find_executable() works with ".exe". shutil.which() won't find "rst2man.py" if ".PY" isn't in PATHEXT. The proper behavior, if the CMD shell is the standard of correctness, is to include the exact name as the first candidate to check before trying the name plus the PATHEXT extensions. To be more like the CMD shell, a name without an extension should be excluded, but effectively included anyway if PATHEXT contains a "." entry.

----------

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


More information about the Python-bugs-list mailing list