pypa/pip · error · PylockSelectError
Multiple packages with the name {package.name!r} are selecte
Error message
Multiple packages with the name {package.name!r} are selected at packages[{package_index}] and packages[{selected_packages_by_name[package.name][0]}] What it means
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.
Source
Thrown at src/pip/_vendor/packaging/pylock.py:845
if package.marker and not package.marker.evaluate(env, context="lock_file"):
continue
# #. If :ref:`pylock-packages-requires-python` is specified, check if it is
# satisfied; an error MUST be raised if it isn't.
if package.requires_python and not package.requires_python.contains(
env_python_full_version,
):
raise PylockSelectError(
f"python_full_version {env_python_full_version!r} "
f"in provided environment does not satisfy the Python version "
f"requirement {str(package.requires_python)!r} for package "
f"{package.name!r} at packages[{package_index}]"
)
# #. Check that no other conflicting instance of the package has been slated
# to be installed; an error about the ambiguity MUST be raised otherwise.
if package.name in selected_packages_by_name:
raise PylockSelectError(
f"Multiple packages with the name {package.name!r} are "
f"selected at packages[{package_index}] and "
f"packages[{selected_packages_by_name[package.name][0]}]"
)
# #. Check that the source of the package is specified appropriately (i.e.
# there are no conflicting sources in the package entry);
# an error MUST be raised if any issues are found.
# Covered by lock.validate() which is a precondition for this method.
# #. Add the package to the set of packages to install.
selected_packages_by_name[package.name] = (package_index, package)
# #. For each package to be installed:
for package_index, package in selected_packages_by_name.values():
# - If :ref:`pylock-packages-vcs` is set:
if package.vcs is not None:
yield package, package.vcsView on GitHub (pinned to d7d0d0a394)
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.
Example fix
# before: both entries match on the same interpreter [[packages]] name = "foo" marker = "python_version >= '3.8'" [[packages]] name = "foo" marker = "python_version >= '3.10'" # after: mutually exclusive [[packages]] name = "foo" marker = "python_version < '3.10'" [[packages]] name = "foo" marker = "python_version >= '3.10'"
Defensive patterns
Strategy: validation
Validate before calling
from collections import Counter
from pip._vendor.packaging.markers import Marker
def has_duplicate_selected_packages(packages, env):
selected = [p['name'] for p in packages
if (not p.get('marker')) or Marker(p['marker']).evaluate(env)]
return [n for n, c in Counter(selected).items() if c > 1] Type guard
null
Try / catch
from pip._vendor.packaging.pylock import PylockSelectError
try:
list(pylock.select(environment=env))
except PylockSelectError as e:
if 'Multiple packages' in str(e):
make_markers_mutually_exclusive(e) Prevention
- When adding platform-variant entries for the same project, use strictly mutually exclusive markers.
- Lint the lock for duplicate names during authoring.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Provided environment does not satisfy any of the environment
- python_full_version {env_python_full_version!r} in provided
- python_full_version {env_python_full_version!r} in provided
- No wheel found matching the provided tags for package {packa
- Platform and interpreter constraints using --python-version,
AI-assisted analysis of pypa/pip@d7d0d0a394 (2026-08-04).
Data as JSON: /data/errors/3eb3b49cc52733cb.json.
Report an issue: GitHub.