PyO3/pyo3 · error
Unrecognized TARGET environment variable value
Error message
Unrecognized TARGET environment variable value
What it means
Panic while parsing the TARGET environment variable into a Triple: the value exists but does not parse as a known Rust target triple (malformed, custom, or unsupported string), so the .parse().expect() aborts. The faulty input is the TARGET value itself as set by Cargo or the environment.
Solutions
- Check the --target argument / TARGET value for typos or stray characters
- Use a triple known to rustc (rustc --print target-list)
- For custom targets, extend parsing in pyo3-build-config to recognize the triple
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at pyo3-build-config/src/impl_.rs:74 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of PyO3/pyo3@ac9b6899d3 (2026-09-05).
Data as JSON: /api/errors/656640409cfaf6a5.
Report an issue: GitHub.
Appendix: source
Thrown at pyo3-build-config/src/impl_.rs:74
pub fn env_var(var: &str) -> Option<OsString> {
println!("cargo:rerun-if-env-changed={var}");
#[cfg(test)]
{
READ_ENV_VARS.with(|env_vars| {
env_vars.borrow_mut().push(var.to_owned());
});
}
env::var_os(var)
}
/// Gets the compilation target triple from environment variables set by Cargo.
///
/// Must be called from a crate build script.
pub fn target_triple_from_env() -> Triple {
env::var("TARGET")
.expect("target_triple_from_env() must be called from a build script")
.parse()
.expect("Unrecognized TARGET environment variable value")
}
fn sanitize_stable_abi_version(
stable_abi_version: Option<PythonVersion>,
version: PythonVersion,
) -> Result<PythonVersion> {
if let Some(min_version) = stable_abi_version {
ensure!(
min_version <= version,
"cannot set a minimum Python version {} higher than the interpreter version {} \
(the minimum Python version is implied by the abi3-py3{} feature)",
min_version,
version,
min_version.minor
);
Ok(min_version)
} else {
Ok(version)View on GitHub (pinned to ac9b6899d3)