{"record":{"id":"1c52f819e3998c1b","repo":"pypa/pip","slug":"requested-self-ireq-has-inconsistent-self-field","errorCode":null,"errorMessage":"Requested {self.ireq} has inconsistent {self.field}: expected {self.f_val!r}, but metadata has {self.m_val!r}","messagePattern":"Requested (.+?) has inconsistent (.+?): 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/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/resolution/resolvelib/candidates.py#L204-L240","documentation":"_check_metadata_consistency (candidates.py:221-227) raises MetadataInconsistent for the 'name' field when the prepared distribution's canonical_name differs from the name pip expected (derived from the sdist/wheel filename, #egg= fragment, or the install requirement name). This catches artifacts whose filename label doesn't match their internal METADATA Name.","triggerScenarios":"A wheel or sdist whose filename-derived name disagrees with the Name in its METADATA — e.g. a renamed wheel, a fork published under a different filename, or a stale #egg= override.","commonSituations":"Manually renamed wheel files; cached wheel from a renamed/forked project; #egg=oldname on a URL pointing to a differently-named project.","solutions":["Fix the artifact filename to match its METADATA Name.","Remove any #egg= override on the requirement URL.","Clear the pip cache (pip cache purge) and re-download from a trusted source."],"exampleFix":"# before\npip install ./renamed_foo-1.0.whl   # METADATA says Name: foo\n# after (rename file to match metadata)\nmv renamed_foo-1.0.whl foo-1.0.whl && pip install ./foo-1.0.whl","handlingStrategy":"validation","validationCode":"# Before installing a wheel, check filename name matches METADATA Name.\nimport zipfile, re, sys\nwhl = sys.argv[1]\nfname_name = re.split(r\"-\", whl)[0].lower().replace(\"_\", \"-\")\nwith zipfile.ZipFile(whl) as z:\n    meta = [n for n in z.namelist() if n.endswith(\"/METADATA\") or n.endswith(\"METADATA\")][0]\n    for line in z.read(meta).decode().splitlines():\n        if line.lower().startswith(\"name:\"):\n            meta_name = line.split(\":\", 1)[1].strip().lower()\n            assert fname_name == meta_name, f\"Filename {fname_name} != METADATA {meta_name}\"\n            print(\"OK\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never rename wheel files after building them.","Drop #egg= overrides; let metadata define the name.","Clear the wheel cache after renaming/forking a project."],"tags":["metadata","name-mismatch","resolver"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}