{"record":{"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/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/operations/prepare.py#L529-L565","documentation":"Raised by _fetch_metadata_using_link_data_attr (prepare.py:546) as MetadataInconsistent when the Name field in a fetched metadata-only distribution does not match the name of the InstallRequirement being resolved. This protects against an index returning metadata for a different project than requested (e.g. due to a name-collision or misrouted request).","triggerScenarios":"While fetching PEP 658 / data-dist-info-metadata, the canonicalized Name from the downloaded METADATA differs from canonicalize_name(req.req.name). The metadata was advertised for a link but its Name field names another package.","commonSituations":"A typo or casing mismatch where the requested name doesn't match the project's actual canonical name; a mirror/index routing bug returning the wrong project's metadata; name-squatting or a rename where old/new names diverge.","solutions":["Verify the exact canonical project name on PyPI and correct the requirement spelling.","Switch to the official PyPI to rule out an index routing problem.","Clear the local cache in case a stale metadata file was cached.","If you publish the package, ensure the Name field in METADATA matches the distribution filename."],"exampleFix":"# before\npip install Django-ORM   # wrong/colliding name\n# after\npip install --no-cache-dir django","handlingStrategy":"validation","validationCode":"from pip._vendor.packaging.utils import canonicalize_name\n\ndef requested_name_matches(req_name: str, metadata_name: str) -> bool:\n    return canonicalize_name(req_name) == canonicalize_name(metadata_name)\n\n# Before install: fetch the index metadata name and compare.\nimport requests, json\n\ndef pypi_name_for(project: str) -> str:\n    data = requests.get(f\"https://pypi.org/pypi/{project}/json\", timeout=30).json()\n    return data['info']['name']","typeGuard":"from pip._vendor.packaging.utils import canonicalize_name\n\ndef names_agree(requested: str, actual: str) -> bool:\n    return canonicalize_name(requested) == canonicalize_name(actual)","tryCatchPattern":"from subprocess import run, CalledProcessError\ntry:\n    run([\"pip\", \"install\", pkg], check=True)\nexcept CalledProcessError:\n    # Retry against the official index / corrected canonical name.\n    run([\"pip\", \"install\", \"--no-cache-dir\", \"-i\", \"https://pypi.org/simple/\", canonical_name], check=True)","preventionTips":["Use the canonical project name exactly as published on PyPI.","Validate names against the project's metadata before scripted installs.","Clear pip cache to drop a stale mismatched metadata file."],"tags":["metadata","name","pep658","index","validation","pip"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}