{"record":{"id":"610075b6846b24fa","repo":"PyO3/pyo3","slug":"pyo3-build-config-get-requires-a-direct-depen","errorCode":null,"errorMessage":"`pyo3_build_config::get()` requires a direct dependency on `pyo3` or `pyo3-ffi`","messagePattern":"`pyo3_build_config::get\\(\\)` requires a direct dependency on `pyo3` or `pyo3-ffi`","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pyo3-build-config/src/lib.rs","lineNumber":145,"sourceCode":"        if let Some(framework_prefix) = interpreter_config.python_framework_prefix() {\n            writeln!(writer, \"cargo:rustc-link-arg=-Wl,-rpath,{framework_prefix}\").unwrap();\n        }\n    }\n}\n\n/// Loads the configuration determined from the build environment.\n///\n/// This function must be called from a build script, and requires a direct dependency on at\n/// least one of `pyo3` or `pyo3-ffi`.\npub fn get() -> &'static InterpreterConfig {\n    static CONFIG: LazyLock<InterpreterConfig> = LazyLock::new(get_inner);\n    &CONFIG\n}\n\n#[track_caller]\nfn get_inner() -> InterpreterConfig {\n    let Some(interpreter_config) = InterpreterConfig::from_cargo_dep_env() else {\n        panic!(\"`pyo3_build_config::get()` requires a direct dependency on `pyo3` or `pyo3-ffi`\")\n    };\n    interpreter_config.expect(\"failed to parse PyO3 config\")\n}\n\n/// Registers `pyo3`s config names as reachable cfg expressions.\n///\n/// - <https://github.com/rust-lang/cargo/pull/13571>\n/// - <https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-check-cfg>\n#[doc(hidden)]\npub fn print_expected_cfgs() {\n    println!(\"cargo:rustc-check-cfg=cfg(Py_LIMITED_API)\");\n    println!(\"cargo:rustc-check-cfg=cfg(Py_GIL_DISABLED)\");\n    println!(\"cargo:rustc-check-cfg=cfg(PyPy)\");\n    println!(\"cargo:rustc-check-cfg=cfg(GraalPy)\");\n    println!(\"cargo:rustc-check-cfg=cfg(RustPython)\");\n    println!(\n        r#\"cargo:rustc-check-cfg=cfg(py_sys_config, values(\"Py_DEBUG\", \"Py_REF_DEBUG\", \"Py_TRACE_REFS\", \"COUNT_ALLOCS\"))\"#\n    );","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/PyO3/pyo3/blob/ac9b6899d348be4d54614d060dea53a645a12e36/pyo3-build-config/src/lib.rs#L127-L163","documentation":"pyo3_build_config::get() reads the interpreter config from the CARGO manifest dependency environment (DEP_ variables) that only exist when you depend directly on pyo3 or pyo3-ffi. If neither dependency link is present, get_inner panics because there is no config to load.","triggerScenarios":"Calling pyo3_build_config::get() from a build script of a crate that does not directly depend on pyo3 or pyo3-ffi (e.g. only transitive dependency, so no DEP_PYTHON_PYO3_CONFIG env var).","commonSituations":"Crate moved pyo3 to a transitive dependency; depending only on pyo3-build-config directly; build script of an indirect helper crate expecting config set by another crate.","solutions":["Add pyo3 (or pyo3-ffi) as a direct dependency in Cargo.toml so Cargo exposes DEP_PYTHON_PYO3_CONFIG","Use pyo3-build-config's own APIs (e.g. from_interpreter/from_cargo_dep_env-equivalent setup) instead of get() if you don't depend on pyo3","Verify your build script runs in a crate where the DEP_ env var is set: `println!(\"{:?}\", std::env::var(\"DEP_PYTHON_PYO3_CONFIG\"))`"],"exampleFix":"// before: only pyo3-build-config in build-dependencies\n[build-dependencies]\npyo3-build-config = \"0.22\"\n// after\n[build-dependencies]\npyo3-build-config = \"0.22\"\n[dependencies]\npyo3 = \"0.22\"","handlingStrategy":"validation","validationCode":"if std::env::var(\"DEP_PYTHON_PYO3_CONFIG\").is_err() {\n    panic!(\"add a direct dependency on pyo3 or pyo3-ffi before calling pyo3_build_config::get()\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Declare pyo3 or pyo3-ffi as a direct dependency of the crate whose build script needs config","Check for the DEP_PYTHON_PYO3_CONFIG env var at the start of your build script","Don't rely on transitive dependencies to expose DEP_ links"],"tags":["cargo","build-script","missing-dependency","panic"],"backgroundTag":"missing-direct-dependency","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"}