pypa/pip · error · InstallationError

Cannot select requirements from pylock file {pylock_path_or_

Error message

Cannot select requirements from pylock file {pylock_path_or_url!r}: {exc}

What it means

Raised after a pylock file parses successfully but pip cannot run its internal `select()` step, which picks one concrete artifact (wheel/sdist/vcs/directory) per package from the lock. Any exception from that selection logic is wrapped as InstallationError with the lock file path and the underlying cause. It indicates a structurally-valid lock whose contents still cannot be resolved to installable requirements.

Source

Thrown at src/pip/_internal/utils/pylock.py:297

        raise
    except Exception as exc:
        raise InstallationError(
            f"Error reading pylock file {pylock_path_or_url!r}: {exc}"
        ) from exc

    try:
        lock = Pylock.from_dict(tomllib.loads(pylock_content))
    except Exception as exc:
        raise InstallationError(
            f"Invalid pylock file {pylock_path_or_url!r}: {exc}"
        ) from exc

    try:
        # TODO: for completeness, pylock.select should support preferring sdist
        # over wheels to support --no-binary
        yield from lock.select()
    except Exception as exc:
        raise InstallationError(
            f"Cannot select requirements from pylock file {pylock_path_or_url!r}: {exc}"
        ) from exc

View on GitHub (pinned to d7d0d0a394)

Solutions

  1. Run pip with `-v` to expose the underlying exception chained under this message.
  2. Regenerate the lock on the same platform/interpreter where you install so select() can match an artifact.
  3. Check each package entry has at least one selectable artifact (wheel/sdist/vcs/directory) for your environment.
  4. Upgrade pip to a version whose PEP 751 support matches the lock-version in the file.

Example fix

// before
# lock built on linux, installing on windows -> no wheel matches
pip install pylock.toml

// after
# regenerate including windows wheels, or install on the target platform:
uv lock --python-platform windows
pip install pylock.toml
Defensive patterns

Strategy: validation

Validate before calling

import tomllib, platform
major, minor = platform.python_version_tuple()[:2]
data = tomllib.load(open('pylock.toml','rb'))
has_artifact = any(
    'wheels' in p or 'sdist' in p or 'vcs' in p or 'directory' in p
    for p in data.get('packages', [])
)
if not has_artifact:
    raise SystemExit('pylock has no installable artifacts for this environment')

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: Invoking select_from_pylock_path_or_url where lock.select() raises — e.g. a package entry has no wheel/sdist/vcs/dir block, has markers that exclude every artifact, references an unsupported package type, or has an inconsistent environment hash. Anything thrown inside Pylock.select bubbles here.

Common situations: Lock file was generated for a different platform/interpreter and select() finds no matching artifact for the current environment; a package entry was edited and is missing its `wheels`/`sdist` subsection; lock-version is supported but uses a newer optional field this pip doesn't know how to select from.

Related errors


AI-assisted analysis of pypa/pip@d7d0d0a394 (2026-08-04). Data as JSON: /data/errors/59e57f6c58475bb4.json. Report an issue: GitHub.