pypa/pip · error · MetadataInconsistent

Requested {self.ireq} has inconsistent {self.field}: expecte

Error message

Requested {self.ireq} has inconsistent {self.field}: expected {self.f_val!r}, but metadata has {self.m_val!r}

What it means

_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.

Source

Thrown at src/pip/_internal/resolution/resolvelib/candidates.py:222

    def version(self) -> Version:
        if self._version is None:
            self._version = self.dist.version
        return self._version

    def format_for_error(self) -> str:
        return (
            f"{self.name} {self.version} "
            f"(from {'editable ' if self.is_editable else ''}"
            f"{self._link.file_path if self._link.is_file else self._link})"
        )

    def _prepare_distribution(self) -> BaseDistribution:
        raise NotImplementedError("Override in subclass")

    def _check_metadata_consistency(self, dist: BaseDistribution) -> None:
        """Check for consistency of project name and version of dist."""
        if self._name is not None and self._name != dist.canonical_name:
            raise MetadataInconsistent(
                self._ireq,
                "name",
                self._name,
                dist.canonical_name,
            )
        if self._version is not None and self._version != dist.version:
            raise MetadataInconsistent(
                self._ireq,
                "version",
                str(self._version),
                str(dist.version),
            )
        # check dependencies are valid
        # TODO performance: this means we iterate the dependencies at least twice,
        # we may want to cache parsed Requires-Dist
        try:
            list(dist.iter_dependencies(list(dist.iter_provided_extras())))
        except InvalidRequirement as e:

View on GitHub (pinned to f399c37189)

Solutions

  1. Fix the artifact filename to match its METADATA Name.
  2. Remove any #egg= override on the requirement URL.
  3. Clear the pip cache (pip cache purge) and re-download from a trusted source.

Example fix

# before
pip install ./renamed_foo-1.0.whl   # METADATA says Name: foo
# after (rename file to match metadata)
mv renamed_foo-1.0.whl foo-1.0.whl && pip install ./foo-1.0.whl
Defensive patterns

Strategy: validation

Validate before calling

# Before installing a wheel, check filename name matches METADATA Name.
import zipfile, re, sys
whl = sys.argv[1]
fname_name = re.split(r"-", whl)[0].lower().replace("_", "-")
with zipfile.ZipFile(whl) as z:
    meta = [n for n in z.namelist() if n.endswith("/METADATA") or n.endswith("METADATA")][0]
    for line in z.read(meta).decode().splitlines():
        if line.lower().startswith("name:"):
            meta_name = line.split(":", 1)[1].strip().lower()
            assert fname_name == meta_name, f"Filename {fname_name} != METADATA {meta_name}"
            print("OK")

Prevention

When it happens

Trigger: 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.

Common situations: Manually renamed wheel files; cached wheel from a renamed/forked project; #egg=oldname on a URL pointing to a differently-named project.

Related errors


AI-assisted analysis of pypa/pip@f399c37189 (2026-08-08). Data as JSON: /api/errors/1c52f819e3998c1b. Report an issue: GitHub.