{"record":{"id":"58e0c913c5771b8a","repo":"astral-sh/uv","slug":"cannot-specify-constraints-with-a-pylock-toml-fi","errorCode":null,"errorMessage":"Cannot specify constraints with a `pylock.toml` file","messagePattern":"Cannot specify constraints with a `pylock\\.toml` file","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/uv-requirements/src/specification.rs","lineNumber":478,"sourceCode":"        // If we have a `pylock.toml`, don't allow additional requirements, constraints, or\n        // overrides.\n        if let Some(pylock_toml) = requirements.iter().find_map(|source| {\n            if let RequirementsSource::PylockToml(path) = source {\n                Some(path)\n            } else {\n                None\n            }\n        }) {\n            if requirements\n                .iter()\n                .any(|source| !matches!(source, RequirementsSource::PylockToml(..)))\n            {\n                return Err(anyhow::anyhow!(\n                    \"Cannot specify additional requirements alongside a `pylock.toml` file\",\n                ));\n            }\n            if !constraints.is_empty() {\n                return Err(anyhow::anyhow!(\n                    \"Cannot specify constraints with a `pylock.toml` file\"\n                ));\n            }\n            if !overrides.is_empty() {\n                return Err(anyhow::anyhow!(\n                    \"Cannot specify overrides with a `pylock.toml` file\"\n                ));\n            }\n\n            // If we have a `pylock.toml`, disallow specifying paths for groups; instead, require\n            // that all groups refer to the `pylock.toml` file.\n            if let Some(groups) = groups {\n                let mut names = Vec::new();\n                for group in &groups.groups {\n                    if group.path.is_some() {\n                        return Err(anyhow::anyhow!(\n                            \"Cannot specify paths for groups with a `pylock.toml` file; all groups must refer to the `pylock.toml` file\"\n                        ));","sourceCodeStart":460,"sourceCodeEnd":496,"githubUrl":"https://github.com/astral-sh/uv/blob/f1a42680ff5272232d65748acf338b19778dde24/crates/uv-requirements/src/specification.rs#L460-L496","documentation":"Thrown in RequirementsSpecification::from_sources (crates/uv-requirements/src/specification.rs:478) when requirements include a pylock.toml and the constraints list is non-empty. Constraints would narrow a resolution, but a pylock.toml is already fully resolved — there is nothing left to constrain — so any --constraints usage alongside it is rejected.","triggerScenarios":"`uv pip install -r pylock.toml --constraints constraints.txt` (constraints list non-empty while a PylockToml source is present in requirements); programmatic from_sources with both populated.","commonSituations":"Users layering corporate pin files on top of a lock; CI templates that always set --constraints; transitioning from constraints-only workflows to locks without dropping the old flags.","solutions":["Drop --constraints from the invocation when installing from pylock.toml","If the pins matter, incorporate them at lock-creation time (regenerate the lock from the constrained project) instead of at install time","Prefer `uv sync` for reproducing a locked environment end-to-end"],"exampleFix":"# before\nuv pip install -r pylock.toml --constraints constraints.txt\n# after\nuv pip install -r pylock.toml","handlingStrategy":"validation","validationCode":"let has_pylock = requirements.iter().any(|s| matches!(s, RequirementsSource::PylockToml(_)));\nif has_pylock && !constraints.is_empty() {\n    return Err(anyhow::anyhow!(\"constraints are not applicable alongside a pylock.toml\"));\n}","typeGuard":"fn is_pylock_source(s: &RequirementsSource) -> bool {\n    matches!(s, RequirementsSource::PylockToml(_))\n}","tryCatchPattern":"match RequirementsSpecification::from_sources(requirements, constraints, /* .. */).await {\n    Err(err) if err.to_string().contains(\"Cannot specify constraints with a `pylock.toml`\") => {\n        // clear the constraints list and retry\n    }\n    spec => spec?,\n}","preventionTips":["Apply constraints at lock-creation time, not install time","Guard CI templates so --constraints is unset when -r points at pylock.toml","Centralize lock invocations so flags cannot be mixed accidentally"],"tags":["uv","pylock-toml","constraints","api-misuse","pip-interface"],"backgroundTag":null,"analyzedSha":"f1a42680ff5272232d65748acf338b19778dde24","analyzedAt":"2026-08-16T04:51:47.599Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}