diff --git a/Cargo.lock b/Cargo.lock index b049d4a0..31c1c4ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1200,6 +1200,15 @@ dependencies = [ "digest", ] +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "html-escape" version = "0.2.13" @@ -2320,6 +2329,7 @@ dependencies = [ "tracing", "tracing-test", "url", + "which", "zip", ] @@ -3668,6 +3678,19 @@ version = "0.25.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" +[[package]] +name = "which" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fa5e0c10bf77f44aac573e498d1a82d5fbd5e91f6fc0a99e7be4b38e85e101c" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", + "windows-sys 0.52.0", +] + [[package]] name = "winapi" version = "0.3.9" diff --git a/crates/rattler_installs_packages/Cargo.toml b/crates/rattler_installs_packages/Cargo.toml index 18e84471..b6949bac 100644 --- a/crates/rattler_installs_packages/Cargo.toml +++ b/crates/rattler_installs_packages/Cargo.toml @@ -71,6 +71,7 @@ async-recursion = "1.0.5" fs-err = "2.11.0" fs_extra = "1.3.0" async_http_range_reader = "0.6.0" +which = "6.0.0" [dev-dependencies] anyhow = "1.0.79" diff --git a/crates/rattler_installs_packages/src/python_env/system_python.rs b/crates/rattler_installs_packages/src/python_env/system_python.rs index b58fb662..12741934 100644 --- a/crates/rattler_installs_packages/src/python_env/system_python.rs +++ b/crates/rattler_installs_packages/src/python_env/system_python.rs @@ -24,7 +24,15 @@ pub fn system_python_executable() -> Result<&'static PathBuf, FindPythonError> { // When installed with homebrew on macOS, the python3 executable is called `python3` instead // Also on some ubuntu installs this is the case // For windows it should just be python - let output = match std::process::Command::new("python3") + let path = which::which("python3") + .or_else(|_| which::which("python")) + .map_err(|_| FindPythonError::NotFound)?; + + // The found binary may not actually refer to the actual python executable, + // this can be because its symlinked, or it's actually a script that invokes python. + // + // Execute the binary itself to determine where the interpreter is located. + let output = match std::process::Command::new(path) .arg("-c") .arg("import sys; print(sys.executable, end='')") .output()