{"record":{"id":"6c01d2831bf9f53b","repo":"PyO3/pyo3","slug":"target-triple-from-env-must-be-called-from-a-bui","errorCode":null,"errorMessage":"target_triple_from_env() must be called from a build script","messagePattern":"target_triple_from_env\\(\\) must be called from a build script","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pyo3-build-config/src/impl_.rs","lineNumber":72,"sourceCode":"/// Gets an external environment variable, and registers the build script to rerun if\n/// the variable changes.\npub fn env_var(var: &str) -> Option<OsString> {\n    println!(\"cargo:rerun-if-env-changed={var}\");\n    #[cfg(test)]\n    {\n        READ_ENV_VARS.with(|env_vars| {\n            env_vars.borrow_mut().push(var.to_owned());\n        });\n    }\n    env::var_os(var)\n}\n\n/// Gets the compilation target triple from environment variables set by Cargo.\n///\n/// Must be called from a crate build script.\npub fn target_triple_from_env() -> Triple {\n    env::var(\"TARGET\")\n        .expect(\"target_triple_from_env() must be called from a build script\")\n        .parse()\n        .expect(\"Unrecognized TARGET environment variable value\")\n}\n\nfn sanitize_stable_abi_version(\n    stable_abi_version: Option<PythonVersion>,\n    version: PythonVersion,\n) -> Result<PythonVersion> {\n    if let Some(min_version) = stable_abi_version {\n        ensure!(\n            min_version <= version,\n            \"cannot set a minimum Python version {} higher than the interpreter version {} \\\n             (the minimum Python version is implied by the abi3-py3{} feature)\",\n            min_version,\n            version,\n            min_version.minor\n        );\n        Ok(min_version)","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/PyO3/pyo3/blob/ac9b6899d348be4d54614d060dea53a645a12e36/pyo3-build-config/src/impl_.rs#L54-L90","documentation":"Panic in target_triple_from_env: the TARGET environment variable, which only Cargo sets when running a build script, is absent because std::env::var(\"TARGET\") failed. The function is a build-script helper; calling it from a normal binary, test, or before Cargo exports TARGET hits this expect.","triggerScenarios":"Thrown at pyo3-build-config/src/impl_.rs:72 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Call target_triple_from_env only from a crate's build.rs","If invoked outside Cargo, set TARGET manually to the desired triple (e.g. x86_64-unknown-linux-gnu)","Use the target_triple crate or restructure the code to receive the triple as a parameter"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}