{"record":{"id":"20f526910daebddf","repo":"PyO3/pyo3","slug":"python-script-failed","errorCode":null,"errorMessage":"Python script failed","messagePattern":"Python script failed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pyo3-build-config/src/impl_.rs","lineNumber":2534,"sourceCode":"        .stdout(Stdio::piped())\n        .stderr(Stdio::inherit())\n        .spawn()\n        .and_then(|mut child| {\n            child\n                .stdin\n                .as_mut()\n                .expect(\"piped stdin\")\n                .write_all(script.as_bytes())?;\n            child.wait_with_output()\n        });\n\n    match out {\n        Err(err) => bail!(\n            \"failed to run the Python interpreter at {}: {}\",\n            interpreter.display(),\n            err\n        ),\n        Ok(ok) if !ok.status.success() => bail!(\"Python script failed\"),\n        Ok(ok) => Ok(String::from_utf8(ok.stdout)\n            .context(\"failed to parse Python script output as utf-8\")?),\n    }\n}\n\nfn venv_interpreter(virtual_env: &OsStr, windows: bool) -> PathBuf {\n    let venv = Path::new(virtual_env);\n    // Rebuild if the virtual environment configuration changes\n    println!(\n        \"cargo:rerun-if-changed={}\",\n        venv.join(\"pyvenv.cfg\").display()\n    );\n    if windows {\n        venv.join(\"Scripts\").join(\"python.exe\")\n    } else {\n        venv.join(\"bin\").join(\"python\")\n    }\n}","sourceCodeStart":2516,"sourceCodeEnd":2552,"githubUrl":"https://github.com/PyO3/pyo3/blob/ac9b6899d348be4d54614d060dea53a645a12e36/pyo3-build-config/src/impl_.rs#L2516-L2552","documentation":"pyo3 probes the Python interpreter by piping an inspection script and checking the exit status. If the interpreter runs but exits with a non-zero status, the build fails with the terse message 'Python script failed'. The interpreter's stderr is surfaced by cargo, so the real cause is usually printed just above this error.","triggerScenarios":"run_python_script's child process returns Ok(output) with !output.status.success() — i.e. the interpreter started but the probe script (importing sys, reading sysconfig vars like EXT_SUFFIX / Py_GIL_DISABLED) crashed or the interpreter aborted.","commonSituations":"A broken/incompatible interpreter that crashes on startup (partially installed Python, conflicting site-packages, missing DLLs on Windows); a wrapper script that exits non-zero; GraalPy/PyPy builds that fail importing required modules; wrong interpreter architecture for the OS.","solutions":["Run the failing interpreter manually and reproduce: `<path> -c \"import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))\"` to see the real error","Point PYO3_PYTHON at a known-good interpreter and rebuild","Reinstall or repair the broken Python installation","Check the interpreter's stderr output printed above the error by cargo for the root cause"],"exampleFix":"// shell, before\nexport PYO3_PYTHON=/mnt/broken/python  # crashes on start\n// after\nexport PYO3_PYTHON=$(which python3) && cargo build","handlingStrategy":"validation","validationCode":"// shell\n${PYO3_PYTHON:-python3} -c 'import sys, sysconfig; print(sys.version); print(sysconfig.get_config_var(\"EXT_SUFFIX\"))' >/dev/null || echo 'probe fails: interpreter broken; see its stderr'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Read the interpreter stderr cargo prints above this error","Test new Python distributions with a probe command before wiring them into builds","Keep interpreter installs intact; reinstall on partial-upgrade failures"],"tags":["rust","pyo3","python-interpreter","script-failure","build-time"],"backgroundTag":"interpreter-script-failed","analyzedSha":"ac9b6899d348be4d54614d060dea53a645a12e36","analyzedAt":"2026-09-05T09:20:35.319Z","contentChangedAt":"2026-09-05T09:20:35.319Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}