{"record":{"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":874,"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":856,"sourceCodeEnd":892,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_vendor/packaging/pylock.py#L856-L892","documentation":"PylockSelectError raised by Pylock.select when two distinct package entries share the same name and both are selected (their markers both match the environment). PEP 751 forbids installing two versions of one distribution simultaneously, so ambiguity is rejected and both array indices are reported.","triggerScenarios":"In the select() loop, selected_packages_by_name tracks already-selected package names; when a later packages[j] has the same name as an earlier packages[i] and both pass their markers, the check 'package.name in selected_packages_by_name' fires, reporting packages[j] and packages[i].","commonSituations":"Lock accidentally lists the same distribution twice (e.g. once as a wheel package and once as a VCS source); two entries that differ only by marker but both markers match the current environment; a merge of two lock files creating duplicates.","solutions":["Inspect packages[index] and packages[other_index] named in the message; they share a name.","Tighten each entry's 'marker' so only one can match any given environment (e.g. platform-specific splits), OR delete the duplicate entry.","If one is a direct (VCS/directory) source and the other is a wheel for the same project, merge them into a single package entry with the appropriate source fields.","Regenerate the lock from a clean dependency set to avoid duplicates."],"exampleFix":"# before: two entries both named \"requests\", both markers match Linux\n[[packages]]\nname = \"requests\"\nversion = \"2.31.0\"\nmarker = \"platform_system == 'Linux'\"\n[[packages]]\nname = \"requests\"\nversion = \"2.31.0\"\nmarker = \"platform_machine == 'x86_64'\"\n\n# after: merge into one entry, or make markers mutually exclusive\n[[packages]]\nname = \"requests\"\nversion = \"2.31.0\"\nmarker = \"platform_system == 'Linux' and platform_machine == 'x86_64'\"","handlingStrategy":"validation","validationCode":"from packaging.markers import default_environment\n\ndef no_duplicate_selected_names(pylock, environment=None) -> bool:\n    env = environment or default_environment()\n    seen = {}\n    for i, p in enumerate(pylock.packages):\n        if p.marker and not p.marker.evaluate(env, context='lock_file'):\n            continue\n        if p.name in seen:\n            return False\n        seen[p.name] = i\n    return True\n\nassert no_duplicate_selected_names(pylock, env)","typeGuard":"null","tryCatchPattern":"from packaging.pylock import PylockSelectError\ntry:\n    list(pylock.select(environment=env))\nexcept PylockSelectError as e:\n    # message names both indices; make their markers mutually exclusive or merge\n    report(e)","preventionTips":["Ensure duplicate-named package entries carry mutually exclusive markers.","Avoid merging lock files blindly; deduplicate by name afterwards.","Distinguish a wheel package from a VCS source for the same project by merging into one entry."],"tags":["pylock","packaging","select","naming","conflict"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}