pypa/pip · error · ValueError

Missing 'Version:' header and/or {} file at path: {}

Error message

Missing 'Version:' header and/or {} file at path: {}

What it means

Raised from the Distribution.version property when _get_version() returns None, i.e. neither a cached _version nor a parseable 'Version:' header in the distribution's PKG-INFO/EGG-INFO metadata could be found. The message names the expected metadata file and its path so you can locate the broken distribution.

Source

Thrown at src/pip/_vendor/pkg_resources/__init__.py:3024

            *************************************************************************
            \n\n!!
            """
            warnings.warn(msg, DeprecationWarning)

            return self._parsed_version

    @property
    def version(self):
        try:
            return self._version
        except AttributeError as e:
            version = self._get_version()
            if version is None:
                path = self._get_metadata_path_for_display(self.PKG_INFO)
                msg = ("Missing 'Version:' header and/or {} file at path: {}").format(
                    self.PKG_INFO, path
                )
                raise ValueError(msg, self) from e

            return version

    @property
    def _dep_map(self):
        """
        A map of extra to its list of (direct) requirements
        for this distribution, including the null extra.
        """
        try:
            return self.__dep_map
        except AttributeError:
            self.__dep_map = self._filter_extras(self._build_dep_map())
        return self.__dep_map

    @staticmethod
    def _filter_extras(dm: dict[str | None, list[Requirement]]):
        """

View on GitHub (pinned to d7d0d0a394)

Solutions

  1. Reinstall the named distribution (pip install --force-reinstall <pkg>) to regenerate valid PKG-INFO with a Version header.
  2. Inspect the path printed in the message and confirm the PKG-INFO/METADATA file exists and contains a 'Version:' line; fix the build if missing.
  3. If iterating a working set, skip or guard dist.version access with try/except ValueError for distributions known to lack metadata.

Example fix

# before
distro = pkg_resources.get_distribution('brokenpkg')
print(distro.version)  # raises ValueError

# after
try:
    print(distro.version)
except ValueError:
    subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--force-reinstall', 'brokenpkg'])
Defensive patterns

Strategy: try-catch

Validate before calling

def has_version(dist) -> bool:
    try:
        return dist._get_version() is not None
    except Exception:
        return False
if not has_version(distro):
    # reinstall before reading version
    ...

Type guard

null

Try / catch

try:
    v = dist.version
except ValueError:
    # metadata corrupt; reinstall or skip this dist
    v = None

Prevention

When it happens

Trigger: Accessing dist.version for a Distribution whose metadata is missing, empty, or lacks a 'Version:' line — common with corrupt installs, incomplete wheels, or legacy eggs where PKG-INFO was stripped.

Common situations: A half-installed/corrupted package in site-packages, an sdist built without PEP 440 metadata, a manually unpacked egg missing PKG-INFO, or pkg_resources iterating a working set that contains a broken dist.

Related errors


AI-assisted analysis of pypa/pip@d7d0d0a394 (2026-08-04). Data as JSON: /data/errors/9f3eaa4545709865.json. Report an issue: GitHub.