{"record":{"id":"59e57f6c58475bb4","repo":"pypa/pip","slug":"cannot-select-requirements-from-pylock-file-pyloc","errorCode":null,"errorMessage":"Cannot select requirements from pylock file {pylock_path_or_url!r}: {exc}","messagePattern":"Cannot select requirements from pylock file (.+?): (.+?)","errorType":"exception","errorClass":"InstallationError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/utils/pylock.py","lineNumber":297,"sourceCode":"        raise\n    except Exception as exc:\n        raise InstallationError(\n            f\"Error reading pylock file {pylock_path_or_url!r}: {exc}\"\n        ) from exc\n\n    try:\n        lock = Pylock.from_dict(tomllib.loads(pylock_content))\n    except Exception as exc:\n        raise InstallationError(\n            f\"Invalid pylock file {pylock_path_or_url!r}: {exc}\"\n        ) from exc\n\n    try:\n        # TODO: for completeness, pylock.select should support preferring sdist\n        # over wheels to support --no-binary\n        yield from lock.select()\n    except Exception as exc:\n        raise InstallationError(\n            f\"Cannot select requirements from pylock file {pylock_path_or_url!r}: {exc}\"\n        ) from exc\n","sourceCodeStart":279,"sourceCodeEnd":300,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/utils/pylock.py#L279-L300","documentation":"Raised as InstallationError by select_from_pylock_path_or_url (pylock.py:297) when the pylock file parses and validates successfully but lock.select() fails to produce requirements. The select() method iterates packages and picks the appropriate entry (wheel, sdist, archive, vcs, directory) for each; if a package has no installable entry, an invalid combination, or an internal error occurs during selection, it propagates here. This is the last-resort error in the pylock loading pipeline.","triggerScenarios":"A valid pylock file where lock.select() raises — e.g. a package entry with no wheel/sdist/archive/vcs/directory sub-table, or a combination of fields that the selection logic cannot handle. The except at line 296 catches it.","commonSituations":"A lock file where a package has an incomplete entry (e.g. name and version but no download artifact). A pylock file generated by a tool with a different selection model than pip expects. Platform-specific entries where no entry matches the current platform.","solutions":["Inspect the chained exception for the specific package and selection failure reason.","Ensure each package in the lock file has at least one valid installable entry (wheel, sdist, archive, vcs, or directory).","If platform-specific: verify the lock file contains an entry compatible with your current platform/Python version.","Regenerate the lock file ensuring all packages resolve to a concrete download artifact."],"exampleFix":"// before (package with no installable artifact)\n[[packages]]\nname = \"pkg\"\nversion = \"1.0\"\n# no wheel/sdist/archive/vcs/directory entry\n\n// after\n[[packages]]\nname = \"pkg\"\nversion = \"1.0\"\n[[packages.sdist]]\nname = \"pkg-1.0.tar.gz\"\nurl = \"https://...\"\nhashes = {sha256 = \"...\"}","handlingStrategy":"validation","validationCode":"import tomllib\nfrom pathlib import Path\n\ndef validate_pylock_packages_have_artifacts(path: str) -> list[str]:\n    \"\"\"Check each package in a pylock file has at least one installable entry.\"\"\"\n    data = tomllib.loads(Path(path).read_text(encoding='utf-8'))\n    artifact_keys = {'vcs', 'directory', 'archive', 'sdist', 'wheels'}\n    problems = []\n    for pkg in data.get('packages', []):\n        if not any(k in pkg and pkg[k] for k in artifact_keys):\n            problems.append(f\"Package {pkg.get('name','?')} has no installable artifact\")\n    return problems","typeGuard":"def package_has_installable_entry(pkg: dict) -> bool:\n    \"\"\"True if a pylock package dict has at least one artifact sub-table.\"\"\"\n    return any(k in pkg and pkg[k] for k in ('vcs', 'directory', 'archive', 'sdist', 'wheels'))","tryCatchPattern":"from pip._internal.exceptions import InstallationError\n\ntry:\n    # pip install -r pylock.toml\n    pass\nexcept InstallationError as e:\n    if 'Cannot select requirements from pylock file' in str(e):\n        # selection failure: inspect each package for missing artifacts\n        pass","preventionTips":["Ensure every package in a lock file has a concrete downloadable artifact (wheel/sdist/archive).","Validate lock files for platform compatibility before distributing.","Test lock file installation in CI on all target platforms before release."],"tags":["pylock","package-selection","validation","lock-file"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}