{"id":"de68125deb486f04","repo":"pypa/pip","slug":"requested-ireq-has-inconsistent-name-expected","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/operations/prepare.py","lineNumber":547,"sourceCode":"            self._download,\n            hashes=metadata_link.as_hashes(),\n        )\n        with open(metadata_file.path, \"rb\") as f:\n            metadata_contents = f.read()\n        # (3) Generate a dist just from those file contents.\n        metadata_dist = get_metadata_distribution(\n            metadata_contents,\n            req.link.filename,\n            req.req.name,\n        )\n        # (4) Ensure the Name: field from the METADATA file matches the name from the\n        #     install requirement.\n        #\n        #     NB: raw_name will fall back to the name from the install requirement if\n        #     the Name: field is not present, but it's noted in the raw_name docstring\n        #     that that should NEVER happen anyway.\n        if canonicalize_name(metadata_dist.raw_name) != canonicalize_name(req.req.name):\n            raise MetadataInconsistent(\n                req, \"Name\", req.req.name, metadata_dist.raw_name\n            )\n        return metadata_dist\n\n    def _fetch_metadata_using_lazy_wheel(\n        self,\n        link: Link,\n    ) -> BaseDistribution | None:\n        \"\"\"Fetch metadata using lazy wheel, if possible.\"\"\"\n        # --use-feature=fast-deps must be provided.\n        if not self.use_lazy_wheel:\n            return None\n        if link.is_file or not link.is_wheel:\n            logger.debug(\n                \"Lazy wheel is not used as %r does not point to a remote wheel\",\n                link,\n            )\n            return None","sourceCodeStart":529,"sourceCodeEnd":565,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_internal/operations/prepare.py#L529-L565","documentation":"Raised as MetadataInconsistent for the Name field when the canonicalized project name read from a PEP 658 .metadata file does not match the name of the InstallRequirement. At prepare.py:546-549, _fetch_metadata_using_link_data_attr compares canonicalize_name(metadata_dist.raw_name) to canonicalize_name(req.req.name); a mismatch aborts before the metadata is used for resolution. raw_name falls back to the requirement name only if the Name field is absent, which the code notes should never happen.","triggerScenarios":"The index's .metadata file for a link declares a Name that canonicalizes differently from the requirement name pip is resolving. E.g. requirement is 'MyPkg' but the .metadata Name is 'otherpkg'. Distinct from the sidecar-vs-wheel check (109); this compares sidecar Name against the requirement itself.","commonSituations":"A misconfigured index mapping a requirement to the wrong .metadata file, a renamed package, or a CDN cache key collision serving the wrong metadata. Also a typo or alias mismatch in a private index.","solutions":["Clear caches: pip cache purge and any HTTP cache, then retry.","Reinstall from the official index: pip install --index-url https://pypi.org/simple/ <pkg>.","Verify the package name spelling and any aliasing in your requirements file.","Pin the exact version and, if possible, a direct wheel URL with a hash to bypass sidecar metadata."],"exampleFix":"# before: requirement name mismatches the served metadata Name\npip install mypkg  # index serves metadata Name 'otherpkg'\n\n# after: correct name / official index\npip install --index-url https://pypi.org/simple/ otherpkg","handlingStrategy":"validation","validationCode":"from pip._vendor.packaging.utils import canonicalize_name\n\ndef validate_metadata_name(metadata_name, requirement_name):\n    if canonicalize_name(metadata_name) != canonicalize_name(requirement_name):\n        raise ValueError(\n            f\"metadata Name {metadata_name!r} != requirement name {requirement_name!r}\"\n        )","typeGuard":"from pip._vendor.packaging.utils import canonicalize_name\ndef names_canonical_equal(a: str, b: str) -> bool:\n    return canonicalize_name(a) == canonicalize_name(b)","tryCatchPattern":null,"preventionTips":["Use the canonical package name in requirements files.","Pin exact versions from a trusted index to avoid metadata-name mismatches.","Purge caches on first occurrence to rule out client-side staleness."],"tags":["metadata","pep658","packaging","name-mismatch","install"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}