{"record":{"id":"34f50b0f12fafadc","repo":"tracel-ai/burn","slug":"error-running-python-interpreter","errorCode":null,"errorMessage":"error running python interpreter","messagePattern":"error running python interpreter","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-tch/build.rs","lineNumber":74,"sourceCode":"        // https://github.com/PyO3/maturin/blob/243b8ec91d07113f97a6fe74d9b2dcb88086e0eb/src/target.rs#L547\n        let python_interpreter = match os {\n            Os::Windows => PathBuf::from(\"python.exe\"),\n            Os::Linux | Os::Macos => {\n                if env::var_os(\"VIRTUAL_ENV\").is_some() {\n                    PathBuf::from(\"python\")\n                } else {\n                    PathBuf::from(\"python3\")\n                }\n            }\n        };\n        let mut libtorch_include_dirs = vec![];\n        let mut libtorch_lib_dir = None;\n        let cxx11_abi = if env_var_rerun(\"LIBTORCH_USE_PYTORCH\").is_ok() {\n            let output = std::process::Command::new(&python_interpreter)\n                .arg(\"-c\")\n                .arg(PYTHON_PRINT_PYTORCH_DETAILS)\n                .output()\n                .expect(\"error running python interpreter\");\n            let mut cxx11_abi = None;\n            for line in String::from_utf8_lossy(&output.stdout).lines() {\n                match line.strip_prefix(\"LIBTORCH_CXX11: \") {\n                    Some(\"True\") => cxx11_abi = Some(\"1\".to_owned()),\n                    Some(\"False\") => cxx11_abi = Some(\"0\".to_owned()),\n                    _ => {}\n                }\n                if let Some(path) = line.strip_prefix(\"LIBTORCH_INCLUDE: \") {\n                    libtorch_include_dirs.push(PathBuf::from(path))\n                }\n                if let Some(path) = line.strip_prefix(\"LIBTORCH_LIB: \") {\n                    libtorch_lib_dir = Some(PathBuf::from(path))\n                }\n            }\n            match cxx11_abi {\n                Some(cxx11_abi) => cxx11_abi,\n                None => panic!(\"no cxx11 abi returned by python {output:?}\"),\n            }","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-tch/build.rs#L56-L92","documentation":"When `LIBTORCH_USE_PYTORCH` is set, burn-tch's build script asks the Python interpreter (from `PYTHON_SYS_EXECUTABLE` or `python`) to print its PyTorch/libtorch details and `.expect(\"error running python interpreter\")` panics if the process cannot be spawned or its output cannot be captured. This means the Python executable was not found or failed to execute — not that PyTorch is missing from its output. Build of the burn-tch crate aborts.","triggerScenarios":"Setting `LIBTORCH_USE_PYTORCH=1` while building burn-tch when: no `python`/`python3` is on PATH, `PYTHON_SYS_EXECUTABLE` points to a nonexistent file, the interpreter is not executable (permissions), or spawn fails for OS/ABI reasons. The `.expect` fires at build.rs:74 on `Command::new(python).arg(\"-c\")...output()`.","commonSituations":"Clean Docker/CI images without Python installed; venv deactivated so `python` resolves nowhere; pointing `PYTHON_SYS_EXECUTABLE` at a Windows `python.exe` path from WSL or vice versa; conda environments removed after being referenced.","solutions":["Install Python and ensure `python` (or `python3`) is on PATH: `python -c \"import torch\"` must work in the same shell that runs cargo","Set `PYTHON_SYS_EXECUTABLE=/path/to/python` explicitly to the interpreter that has PyTorch installed","Verify `LIBTORCH_USE_PYTORCH` is intentional — if you meant to link a downloaded libtorch instead, unset it and set `LIBTORCH_DIR`/`LIBTORCH_BYPASS_VERSION_CHECK` appropriately","Check the interpreter is executable and matches the platform (permissions, shebang, Windows/WSL path confusion)"],"exampleFix":"// before (shell, building with LIBTORCH_USE_PYTORCH=1 but no python on PATH)\ncargo build -p burn-tch   # panics: error running python interpreter\n// after\nexport PYTHON_SYS_EXECUTABLE=$(which python3)\npython3 -c 'import torch; print(torch.__version__)'  # sanity check\ncargo build -p burn-tch","handlingStrategy":"validation","validationCode":"# run in the same shell/environment as cargo build before setting LIBTORCH_USE_PYTORCH\npython -c 'import torch; import os; print(torch.__version__, torch.__file__)' || echo 'python+torch unavailable'\n[ -n \"$PYTHON_SYS_EXECUTABLE\" ] && [ -x \"$PYTHON_SYS_EXECUTABLE\" ] || which python","typeGuard":null,"tryCatchPattern":"# build-script panic; verify the interpreter spawn works before building:\n\"${PYTHON_SYS_EXECUTABLE:-python}\" -c \"import torch\" || { echo 'python interpreter cannot run torch'; exit 1; }","preventionTips":["Ensure a working Python with PyTorch installed is on PATH before enabling LIBTORCH_USE_PYTORCH","Set PYTHON_SYS_EXECUTABLE explicitly to the interpreter that owns your torch install","Sanity-check with `python -c 'import torch'` in CI before building burn-tch","Alternatively install a prebuilt libtorch and point LIBTORCH_DIR at it instead of relying on Python"],"tags":["build-script","python","libtorch","env-var","compile-time"],"backgroundTag":"python-interpreter-not-found","analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}