{"record":{"id":"e7a7d1d89fecf011","repo":"pypa/pip","slug":"double-requirement-given-install-req-already-i","errorCode":null,"errorMessage":"Double requirement given: {install_req} (already in {existing_req}, name={install_req.name!r})","messagePattern":"Double requirement given: (.+?) \\(already in (.+?), name=(.+?)\\)","errorType":"exception","errorClass":"InstallationError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/resolution/legacy/resolver.py","lineNumber":264,"sourceCode":"\n        try:\n            existing_req: InstallRequirement | None = requirement_set.get_requirement(\n                install_req.name\n            )\n        except KeyError:\n            existing_req = None\n\n        has_conflicting_requirement = (\n            parent_req_name is None\n            and existing_req\n            and not existing_req.constraint\n            and existing_req.extras == install_req.extras\n            and existing_req.req\n            and install_req.req\n            and existing_req.req.specifier != install_req.req.specifier\n        )\n        if has_conflicting_requirement:\n            raise InstallationError(\n                f\"Double requirement given: {install_req} \"\n                f\"(already in {existing_req}, name={install_req.name!r})\"\n            )\n\n        # When no existing requirement exists, add the requirement as a\n        # dependency and it will be scanned again after.\n        if not existing_req:\n            requirement_set.add_named_requirement(install_req)\n            # We'd want to rescan this requirement later\n            return [install_req], install_req\n\n        # Assume there's no need to scan, and that we've already\n        # encountered this for scanning.\n        if install_req.constraint or not existing_req.constraint:\n            return [], existing_req\n\n        does_not_satisfy_constraint = install_req.link and not (\n            existing_req.link and install_req.link.path == existing_req.link.path","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/resolution/legacy/resolver.py#L246-L282","documentation":"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.","triggerScenarios":"A requirements file (or CLI args) lists the same package twice with incompatible specifiers, e.g. `pkg>=1` and `pkg<1`.","commonSituations":"Duplicate lines in requirements.txt; a constraints file and a requirement line that disagree; merge conflicts leaving duplicate deps.","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."],"exampleFix":"# before (requirements.txt)\npkg>=1\npkg<=2\n# after\npkg>=1,<=2","handlingStrategy":"validation","validationCode":"# Detect duplicate/conflicting specifiers in a requirements file before install.\nimport re, collections\nlines = [l.strip() for l in open(\"requirements.txt\") if l.strip() and not l.startswith(\"#\")]\nnames = collections.defaultdict(list)\nfor l in lines:\n    m = re.match(r\"([A-Za-z0-9_.-]+)\", l)\n    if m:\n        names[m.group(1).lower()].append(l)\nfor pkg, specs in names.items():\n    if len(specs) > 1 and len(set(specs)) > 1:\n        print(f\"CONFLICT: {pkg} appears as {specs}\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["requirements","conflict","resolver"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}