Check the argument to --python is executable
@@ -71,17 +71,20 @@ def identify_python_interpreter(python: str) -> Optional[str]:
if py:
return py
- # TODO: On Windows, `--python .venv/Scripts/python` won't pass the
- # exists() check (no .exe extension supplied). But it's pretty
- # obvious what the user intends. Should we allow this?
+ # If the named file exists, and is executable, use it.
+ # If it's a directory, assume it's a virtual environment and
+ # look for the environment's Python executable.
if os.path.exists(python):
- if not os.path.isdir(python):
- return python
- # Might be a virtual environment
+ # Do the directory check first because directories can be executable
+ if os.path.isdir(python):
+ # bin/python for Unix, Scripts/python.exe for Windows
+ # Try both in case of odd cases like cygwin.
for exe in ("bin/python", "Scripts/python.exe"):
py = os.path.join(python, exe)
if os.path.exists(py):
return py
+ elif os.access(python, os.X_OK):
+ return python
# Could not find the interpreter specified
return None
