PyO3/pyo3 · error
Python stdout len didn't return expected number of lines: {}
Error message
Python stdout len didn't return expected number of lines: {} What it means
Sanity check after running a small sysconfig query script with the target interpreter: the number of lines captured from the interpreter's stdout does not match the number of print statements the script emitted. The faulty input is the interpreter's output — truncated, buffered, or polluted (e.g. site banner noise) — so the build flags cannot be parsed reliably.
Source
Thrown at pyo3-build-config/src/impl_.rs:1919
if cfg!(windows) {
let script = String::from("import sys;print(sys.version_info < (3, 13))");
let stdout = run_python_script(interpreter.as_ref(), &script)?;
if stdout.trim_end() == "True" {
return Ok(Self::new());
}
}
let mut script = String::from("import sysconfig\n");
script.push_str("config = sysconfig.get_config_vars()\n");
for k in &BuildFlags::ALL {
use std::fmt::Write;
writeln!(&mut script, "print(config.get('{k}', '0'))").unwrap();
}
let stdout = run_python_script(interpreter.as_ref(), &script)?;
let split_stdout: Vec<&str> = stdout.trim_end().lines().collect();
ensure!(
split_stdout.len() == BuildFlags::ALL.len(),
"Python stdout len didn't return expected number of lines: {}",
split_stdout.len()
);
let flags = BuildFlags::ALL
.iter()
.zip(split_stdout)
.filter(|(_, flag_value)| *flag_value == "1")
.map(|(flag, _)| flag.clone())
.collect();
Ok(Self(flags).fixup())
}
fn fixup(mut self) -> Self {
if self.0.contains(&BuildFlag::Py_DEBUG) {
self.0.insert(BuildFlag::Py_REF_DEBUG);
}View on GitHub (pinned to ac9b6899d3)
Solutions
- Run the failing interpreter manually with -c "import sysconfig; ..." and inspect its stdout for extra output or truncation
- Disable site banners/user site packages (e.g. python -S) or print statements in sitecustomize that pollute stdout
- Use a clean, unmodified interpreter installation for the build
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at pyo3-build-config/src/impl_.rs:1919 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/65757b7cb557cd61.
Report an issue: GitHub.