{"record":{"id":"642f84e15a68f7d2","repo":"astral-sh/uv","slug":"cannot-specify-additional-requirements-alongside-a","errorCode":null,"errorMessage":"Cannot specify additional requirements alongside a `pylock.toml` file","messagePattern":"Cannot specify additional requirements alongside a `pylock\\.toml` file","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/uv-requirements/src/specification.rs","lineNumber":473,"sourceCode":"                \"Cannot use `{}` as an exclude file\",\n                pylock_toml.user_display()\n            ));\n        }\n\n        // 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();","sourceCodeStart":455,"sourceCodeEnd":491,"githubUrl":"https://github.com/astral-sh/uv/blob/f1a42680ff5272232d65748acf338b19778dde24/crates/uv-requirements/src/specification.rs#L455-L491","documentation":"Thrown in RequirementsSpecification::from_sources (crates/uv-requirements/src/specification.rs:473) when the requirements list mixes a PylockToml source with any non-pylock source. A pylock.toml is a fully-resolved lock: uv installs exactly what it contains, so extra requirements alongside it are contradictory and rejected before resolution.","triggerScenarios":"`uv pip install -r pylock.toml flask` (a second -r file, a positional package, an --editable, etc. next to the lock); programmatically, requirements containing both PylockToml and any other variant.","commonSituations":"Users adding one ad-hoc package to a locked invocation; CI templates that append `--requirement pylock.toml` to commands that already carry packages; migrating scripts incrementally to locks.","solutions":["Remove the extra requirements/packages from the command and install from the lock alone","Or regenerate the lock including the new package, then install from the updated pylock.toml","If you need a superset, layer with constraints (a requirements.txt pin file) rather than adding requirements next to the lock — but see error 57: constraints are also disallowed, so the lock must be edited"],"exampleFix":"# before\nuv pip install -r pylock.toml flask\n# after\n# add flask to the source project, re-export, then:\nuv pip install -r pylock.toml","handlingStrategy":"validation","validationCode":"let has_pylock = requirements.iter().any(|s| matches!(s, RequirementsSource::PylockToml(_)));\nlet has_other = requirements.iter().any(|s| !matches!(s, RequirementsSource::PylockToml(_)));\nif has_pylock && has_other {\n    return Err(anyhow::anyhow!(\"pylock.toml must be the sole requirements source\"));\n}","typeGuard":"fn is_pylock_source(s: &RequirementsSource) -> bool {\n    matches!(s, RequirementsSource::PylockToml(_))\n}","tryCatchPattern":"match RequirementsSpecification::from_sources(requirements, /* .. */).await {\n    Err(err) if err.to_string().contains(\"additional requirements alongside\") => {\n        // drop extras, regenerate the lock, and retry\n    }\n    spec => spec?,\n}","preventionTips":["Treat a lock install as exclusive: no positional packages or extra -r files","In wrappers, short-circuit when a PylockToml source is present and other sources exist","Regenerate the lock instead of ad-hoc additions"],"tags":["uv","pylock-toml","requirements","api-misuse","pip-interface"],"backgroundTag":null,"analyzedSha":"f1a42680ff5272232d65748acf338b19778dde24","analyzedAt":"2026-08-16T04:51:47.599Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}