{"id":"aaddb2fface5d624","repo":"pypa/pip","slug":"requested-ireq-has-inconsistent-version-expecte","errorCode":null,"errorMessage":"Requested {ireq} has inconsistent version: expected {f_val!r}, but metadata has {m_val!r}","messagePattern":"Requested (.+?) has inconsistent version: expected (.+?), but metadata has (.+?)","errorType":"exception","errorClass":"MetadataInconsistent","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/resolution/resolvelib/candidates.py","lineNumber":229,"sourceCode":"            f\"{self.name} {self.version} \"\n            f\"(from {'editable ' if self.is_editable else ''}\"\n            f\"{self._link.file_path if self._link.is_file else self._link})\"\n        )\n\n    def _prepare_distribution(self) -> BaseDistribution:\n        raise NotImplementedError(\"Override in subclass\")\n\n    def _check_metadata_consistency(self, dist: BaseDistribution) -> None:\n        \"\"\"Check for consistency of project name and version of dist.\"\"\"\n        if self._name is not None and self._name != dist.canonical_name:\n            raise MetadataInconsistent(\n                self._ireq,\n                \"name\",\n                self._name,\n                dist.canonical_name,\n            )\n        if self._version is not None and self._version != dist.version:\n            raise MetadataInconsistent(\n                self._ireq,\n                \"version\",\n                str(self._version),\n                str(dist.version),\n            )\n        # check dependencies are valid\n        # TODO performance: this means we iterate the dependencies at least twice,\n        # we may want to cache parsed Requires-Dist\n        try:\n            list(dist.iter_dependencies(list(dist.iter_provided_extras())))\n        except InvalidRequirement as e:\n            raise MetadataInvalid(self._ireq, str(e))\n\n    def _prepare(self) -> BaseDistribution:\n        try:\n            dist = self._prepare_distribution()\n        except HashError as e:\n            # Provide HashError the underlying ireq that caused it. This","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_internal/resolution/resolvelib/candidates.py#L211-L247","documentation":"MetadataInconsistent raised when the version inferred for the InstallRequirement (from filename, specifier, or metadata sidecar) disagrees with the version in the finally-prepared distribution metadata. This protects the resolver from installing a candidate whose graph was computed against a different version than what actually ships.","triggerScenarios":"self._version is not None and self._version != dist.version after _prepare_distribution(). Happens with URL/path installs whose filename implies 1.0 but whose metadata says 1.0.1; with PEP 658 .metadata sidecars that disagree with the wheel's embedded METADATA (see also SidecarMetadataInconsistent); or with republished/misnamed files on an index.","commonSituations":"A wheel was re-uploaded under an old filename after a version bump; a private index serves mismatched .metadata sidecars; a local sdist whose VERSION/__version__ differs from the filename; partial/failed re-publish to a mirror.","solutions":["Reinstall from the canonical index/PyPI where filename and metadata agree.","Rebuild the local artifact so its version (filename + metadata) is consistent.","If using a private index, fix or purge the mismatched file and its .metadata sidecar.","Pin the version explicitly with == to the value the metadata actually declares."],"exampleFix":"# before - filename says 1.0, metadata says 1.0.1\npip install ./mypkg-1.0.tar.gz\n\n# after - rebuild with consistent version, then install\n# (in mypkg/) bump version to 1.0.1, python -m build\npip install ./mypkg-1.0.1.tar.gz","handlingStrategy":"validation","validationCode":"from packaging.version import Version\n\ndef check_version_matches(filename_version, metadata_version):\n    if Version(filename_version) != Version(metadata_version):\n        raise ValueError(f\"filename version {filename_version} != metadata {metadata_version}\")\n# verify before publishing or pinning a local artifact","typeGuard":null,"tryCatchPattern":"try:\n    pip_install(req)\nexcept InstallationError as e:\n    if 'inconsistent version' in str(e):\n        actual = parse_version_from_error(e)\n        pip_install(f\"{name}=={actual}\")\n    else:\n        raise","preventionTips":["Regenerate artifacts after any version bump so filename and metadata stay in sync.","For private indexes, validate .metadata sidecars match the wheels you serve.","Prefer canonical PyPI artifacts over republished files."],"tags":["pip","resolvelib","metadata","packaging","versioning"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}