Search for python3 in unix virtual environments (#3798)

This commit is contained in:
Zanie Blue 2024-05-23 20:33:34 -04:00 committed by GitHub
parent 73b6a80f23
commit 99b8633ce3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 4 deletions

View file

@ -115,8 +115,19 @@ pub(crate) fn virtualenv_python_executable(venv: impl AsRef<Path>) -> PathBuf {
// If none of these exist, return the standard location
default_executable
} else {
// Search for `python` in the `bin` directory.
venv.join("bin").join("python")
// Check for both `python3` over `python`, preferring the more specific one
let default_executable = venv.join("bin").join("python3");
if default_executable.exists() {
return default_executable;
}
let executable = venv.join("bin").join("python");
if executable.exists() {
return executable;
}
// If none of these exist, return the standard location
default_executable
}
}

View file

@ -152,7 +152,7 @@ fn missing_venv() -> Result<()> {
----- stderr -----
warning: Requirements file requirements.in does not contain any dependencies
error: failed to canonicalize path `[VENV]/bin/python`
error: failed to canonicalize path `[VENV]/bin/python3`
Caused by: No such file or directory (os error 2)
"###
);

View file

@ -119,7 +119,7 @@ fn missing_venv() -> Result<()> {
----- stdout -----
----- stderr -----
error: failed to canonicalize path `[VENV]/bin/python`
error: failed to canonicalize path `[VENV]/bin/python3`
Caused by: No such file or directory (os error 2)
"###);
}