{"id":"963b29637f5ffdff","repo":"pypa/pip","slug":"requested-ireq-has-inconsistent-name-expected-963b29","errorCode":null,"errorMessage":"Requested {ireq} has inconsistent name: expected {f_val!r}, but metadata has {m_val!r}","messagePattern":"Requested (.+?) has inconsistent name: expected (.+?), but metadata has (.+?)","errorType":"exception","errorClass":"MetadataInconsistent","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/resolution/resolvelib/candidates.py","lineNumber":222,"sourceCode":"    def version(self) -> Version:\n        if self._version is None:\n            self._version = self.dist.version\n        return self._version\n\n    def format_for_error(self) -> str:\n        return (\n            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:","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_internal/resolution/resolvelib/candidates.py#L204-L240","documentation":"MetadataInconsistent raised in _check_metadata_consistency when the project name recorded on the InstallRequirement (from filename, #egg=, or requirement line) does not match the canonical name in the built/fetched distribution metadata. pip refuses to proceed because the resolver picked a candidate for one name but the artifact declares another.","triggerScenarios":"self._name is set and self._name != dist.canonical_name after _prepare_distribution(). E.g. requirement `foo @ https://example.com/foo-1.0.tar.gz` whose setup.py/pyproject.toml names the project `Foo-Bar`; or a stale #egg=foo hint pointing at a renamed package; or a yanked/republished index file whose filename name differs from its METADATA name.","commonSituations":"A package was renamed on PyPI but you pinned the old name; a local sdist/wheel whose project_name drifted from its directory name; a mirror or private index serving a file under a mismatched filename; typo in a URL requirement's #egg= fragment.","solutions":["Update the requirement specifier to use the project's actual canonical name as declared in its metadata.","Remove any stale #egg=oldname hint from URL/path requirements.","Rebuild the local sdist/wheel so its filename name matches the metadata project name.","If the index is wrong, report/fix the republished artifact on the private index."],"exampleFix":"# before\npip install \"foo @ https://example.com/foo-1.0.tar.gz#egg=foo\"\n# (metadata actually declares project 'Foo-Bar')\n\n# after\npip install \"foo-bar @ https://example.com/foo-1.0.tar.gz\"","handlingStrategy":"validation","validationCode":"from packaging.utils import canonicalize_name\n\ndef check_name_matches_metadata(req_name, dist_metadata_name):\n    if canonicalize_name(req_name) != canonicalize_name(dist_metadata_name):\n        raise ValueError(\n            f\"requirement name {req_name!r} != metadata name {dist_metadata_name!r}\"\n        )\n# call before pinning: read METADATA/project_name from the artifact and compare","typeGuard":null,"tryCatchPattern":"try:\n    pip_install(req)\nexcept InstallationError as e:\n    if 'inconsistent name' in str(e):\n        # refresh the requirement name from the artifact's actual metadata\n        req = derive_name_from_metadata(artifact_url)\n        pip_install(req)\n    else:\n        raise","preventionTips":["Don't use stale #egg= hints; let pip infer names.","Pin packages by their canonical project name (use `packaging.utils.canonicalize_name`).","Rebuild local artifacts after renaming so filename and metadata agree."],"tags":["pip","resolvelib","metadata","packaging","install"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}