Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions newsfragments/6178.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix build failure when `VIRTUAL_ENV` or `CONDA_PREFIX` is set but the Python interpreter
does not exist at the derived path. PyO3 now checks that the interpreter exists and
falls back to other detection methods with a warning if it does not.
28 changes: 26 additions & 2 deletions pyo3-build-config/src/impl_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2471,8 +2471,32 @@ fn get_env_interpreter() -> Option<PathBuf> {
match (env_var("VIRTUAL_ENV"), env_var("CONDA_PREFIX")) {
// Use cfg rather than CARGO_CFG_TARGET_OS because this affects where files are located on the
// build host
(Some(dir), None) => Some(venv_interpreter(&dir, cfg!(windows))),
(None, Some(dir)) => Some(conda_env_interpreter(&dir, cfg!(windows))),
(Some(dir), None) => {
let path = venv_interpreter(&dir, cfg!(windows));
if path.exists() {
Some(path)
} else {
warn!(
"VIRTUAL_ENV is set to `{}` but no Python interpreter found at `{}`; ignoring",
dir.to_string_lossy(),
path.display()
);
None
}
Comment on lines +2476 to +2485

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do it this way, then the build should almost immediately fail to configure, users will see the warning, and they can decide what to do differently.

Suggested change
if path.exists() {
Some(path)
} else {
warn!(
"VIRTUAL_ENV is set to `{}` but no Python interpreter found at `{}`; ignoring",
dir.to_string_lossy(),
path.display()
);
None
}
if !path.exists() {
warn!(
"VIRTUAL_ENV is set to `{}` but no Python interpreter found at `{}`",
dir.to_string_lossy(),
path.display()
);
}
Some(path)

Same for CONDA_PREFIX below.

}
(None, Some(dir)) => {
let path = conda_env_interpreter(&dir, cfg!(windows));
if path.exists() {
Some(path)
} else {
warn!(
"CONDA_PREFIX is set to `{}` but no Python interpreter found at `{}`; ignoring",
dir.to_string_lossy(),
path.display()
);
None
}
}
(Some(_), Some(_)) => {
warn!(
"Both VIRTUAL_ENV and CONDA_PREFIX are set. PyO3 will ignore both of these for \
Expand Down
Loading