pypa/pip · error · InstallationError
Double requirement given
Error message
Double requirement given: {install_req} (already in {existing_req}, name={install_req.name!r}) What it means
The legacy resolver detects two non-constraint requirements with the same name but different specifiers (resolver.py:254-267: has_conflicting_requirement checks parent_req_name is None, existing_req not constraint, same extras, differing specifiers). It raises InstallationError 'Double requirement' because pip cannot satisfy two contradictory version pins for one package.
Solutions
- Reconcile the two specifiers into a single combined specifier (e.g. pkg>=1,<2).
- Move the version pin into a constraints file (-c) and reference the package once in requirements.
- Remove the duplicate/conflicting line.
Example fix
# before (requirements.txt) pkg>=1 pkg<=2 # after pkg>=1,<=2
Defensive patterns
Strategy: validation
Validate before calling
# Detect duplicate/conflicting specifiers in a requirements file before install.
import re, collections
lines = [l.strip() for l in open("requirements.txt") if l.strip() and not l.startswith("#")]
names = collections.defaultdict(list)
for l in lines:
m = re.match(r"([A-Za-z0-9_.-]+)", l)
if m:
names[m.group(1).lower()].append(l)
for pkg, specs in names.items():
if len(specs) > 1 and len(set(specs)) > 1:
print(f"CONFLICT: {pkg} appears as {specs}") Prevention
- Deduplicate requirements files and lint for repeated package names.
- Use a constraints file (-c) to centralize version pins instead of repeating them.
- Resolve git merge conflicts fully so duplicate dep lines don't linger.
When it happens
Trigger: A requirements file (or CLI args) lists the same package twice with incompatible specifiers, e.g. `pkg>=1` and `pkg<1`.
Common situations: Duplicate lines in requirements.txt; a constraints file and a requirement line that disagree; merge conflicts leaving duplicate deps.
Related errors
- Cannot combine '--path' with '--user' or '--local'
- Cannot use '--only-dependencies' in combination with
- Could not satisfy constraints for
- [dependency-groups] resolution failed for
- Editable requirements are not allowed as constraints
AI-assisted analysis of pypa/pip@f399c37189 (2026-08-08).
Data as JSON: /api/errors/e7a7d1d89fecf011.
Report an issue: GitHub.
Appendix: source
Thrown at src/pip/_internal/resolution/legacy/resolver.py:264
try:
existing_req: InstallRequirement | None = requirement_set.get_requirement(
install_req.name
)
except KeyError:
existing_req = None
has_conflicting_requirement = (
parent_req_name is None
and existing_req
and not existing_req.constraint
and existing_req.extras == install_req.extras
and existing_req.req
and install_req.req
and existing_req.req.specifier != install_req.req.specifier
)
if has_conflicting_requirement:
raise InstallationError(
f"Double requirement given: {install_req} "
f"(already in {existing_req}, name={install_req.name!r})"
)
# When no existing requirement exists, add the requirement as a
# dependency and it will be scanned again after.
if not existing_req:
requirement_set.add_named_requirement(install_req)
# We'd want to rescan this requirement later
return [install_req], install_req
# Assume there's no need to scan, and that we've already
# encountered this for scanning.
if install_req.constraint or not existing_req.constraint:
return [], existing_req
does_not_satisfy_constraint = install_req.link and not (
existing_req.link and install_req.link.path == existing_req.link.pathView on GitHub (pinned to f399c37189)