{"id":"3eb3b49cc52733cb","repo":"pypa/pip","slug":"multiple-packages-with-the-name-package-name-r-a","errorCode":null,"errorMessage":"Multiple packages with the name {package.name!r} are selected at packages[{package_index}] and packages[{selected_packages_by_name[package.name][0]}]","messagePattern":"Multiple packages with the name (.+?) are selected at packages\\[(.+?)\\] and packages\\[(.+?)\\]","errorType":"exception","errorClass":"PylockSelectError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/packaging/pylock.py","lineNumber":845,"sourceCode":"            if package.marker and not package.marker.evaluate(env, context=\"lock_file\"):\n                continue\n\n            # #. If :ref:`pylock-packages-requires-python` is specified, check if it is\n            #    satisfied; an error MUST be raised if it isn't.\n            if package.requires_python and not package.requires_python.contains(\n                env_python_full_version,\n            ):\n                raise PylockSelectError(\n                    f\"python_full_version {env_python_full_version!r} \"\n                    f\"in provided environment does not satisfy the Python version \"\n                    f\"requirement {str(package.requires_python)!r} for package \"\n                    f\"{package.name!r} at packages[{package_index}]\"\n                )\n\n            # #. Check that no other conflicting instance of the package has been slated\n            #    to be installed; an error about the ambiguity MUST be raised otherwise.\n            if package.name in selected_packages_by_name:\n                raise PylockSelectError(\n                    f\"Multiple packages with the name {package.name!r} are \"\n                    f\"selected at packages[{package_index}] and \"\n                    f\"packages[{selected_packages_by_name[package.name][0]}]\"\n                )\n\n            # #. Check that the source of the package is specified appropriately (i.e.\n            #    there are no conflicting sources in the package entry);\n            #    an error MUST be raised if any issues are found.\n            # Covered by lock.validate() which is a precondition for this method.\n\n            # #. Add the package to the set of packages to install.\n            selected_packages_by_name[package.name] = (package_index, package)\n\n        # #. For each package to be installed:\n        for package_index, package in selected_packages_by_name.values():\n            # - If :ref:`pylock-packages-vcs` is set:\n            if package.vcs is not None:\n                yield package, package.vcs","sourceCodeStart":827,"sourceCodeEnd":863,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_vendor/packaging/pylock.py#L827-L863","documentation":"Raised as PylockSelectError (pylock.py:845) by Pylock.select() when two distinct package entries share the same canonical name and both have markers that match the selection environment. The spec forbids ambiguous selections; the error names both conflicting indices.","triggerScenarios":"A lock contains [[packages]] name='foo' twice (e.g. one for Python <3.10 and one for >=3.10) but both entries' markers evaluate True for the current environment. Triggered in the package loop inside select() right after marker evaluation.","commonSituations":"Authoring mutually-exclusive markers incorrectly (both branches true). A lock merge that duplicated an entry. A marker that references a variable not present in the environment so it defaults to truthy in both copies.","solutions":["Make the two packages' markers mutually exclusive for your environment (e.g. 'python_version < \"3.10\"' vs 'python_version >= \"3.10\"').","Remove the duplicate package entry that should not apply.","Provide an environment that disambiguates which entry should win."],"exampleFix":"# before: both entries match on the same interpreter\n[[packages]]\nname = \"foo\"\nmarker = \"python_version >= '3.8'\"\n[[packages]]\nname = \"foo\"\nmarker = \"python_version >= '3.10'\"\n\n# after: mutually exclusive\n[[packages]]\nname = \"foo\"\nmarker = \"python_version < '3.10'\"\n[[packages]]\nname = \"foo\"\nmarker = \"python_version >= '3.10'\"","handlingStrategy":"validation","validationCode":"from collections import Counter\nfrom pip._vendor.packaging.markers import Marker\ndef has_duplicate_selected_packages(packages, env):\n    selected = [p['name'] for p in packages\n                if (not p.get('marker')) or Marker(p['marker']).evaluate(env)]\n    return [n for n, c in Counter(selected).items() if c > 1]","typeGuard":"null","tryCatchPattern":"from pip._vendor.packaging.pylock import PylockSelectError\ntry:\n    list(pylock.select(environment=env))\nexcept PylockSelectError as e:\n    if 'Multiple packages' in str(e):\n        make_markers_mutually_exclusive(e)","preventionTips":["When adding platform-variant entries for the same project, use strictly mutually exclusive markers.","Lint the lock for duplicate names during authoring."],"tags":["pylock","select","markers","duplicate"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}