{"record":{"id":"9f3eaa4545709865","repo":"pypa/pip","slug":"missing-version-header-and-or-file-at-path","errorCode":null,"errorMessage":"Missing 'Version:' header and/or {} file at path: {}","messagePattern":"Missing 'Version:' header and/or (.+?) file at path: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/pkg_resources/__init__.py","lineNumber":3024,"sourceCode":"            *************************************************************************\n            \\n\\n!!\n            \"\"\"\n            warnings.warn(msg, DeprecationWarning)\n\n            return self._parsed_version\n\n    @property\n    def version(self):\n        try:\n            return self._version\n        except AttributeError as e:\n            version = self._get_version()\n            if version is None:\n                path = self._get_metadata_path_for_display(self.PKG_INFO)\n                msg = (\"Missing 'Version:' header and/or {} file at path: {}\").format(\n                    self.PKG_INFO, path\n                )\n                raise ValueError(msg, self) from e\n\n            return version\n\n    @property\n    def _dep_map(self):\n        \"\"\"\n        A map of extra to its list of (direct) requirements\n        for this distribution, including the null extra.\n        \"\"\"\n        try:\n            return self.__dep_map\n        except AttributeError:\n            self.__dep_map = self._filter_extras(self._build_dep_map())\n        return self.__dep_map\n\n    @staticmethod\n    def _filter_extras(dm: dict[str | None, list[Requirement]]):\n        \"\"\"","sourceCodeStart":3006,"sourceCodeEnd":3042,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_vendor/pkg_resources/__init__.py#L3006-L3042","documentation":"Raised as ValueError in the Distribution.version property at line 3019-3024 when _get_version() returns None. This means neither the Distribution object was given an explicit version, nor could a 'Version:' header be found in the PKG-INFO metadata file. The error message includes the PKG_INFO path for diagnosis.","triggerScenarios":"Accessing `dist.version` on a Distribution whose metadata lacks a 'Version:' header. This flows through _get_version() which calls _version_from_file(); if the PKG-INFO file is missing or has no Version line, version resolves to None and the property raises.","commonSituations":"Corrupt or incomplete .egg-info/dist-info directories missing the Version field; manually constructed Distribution objects without a version; old metadata format (pre-PEP 314) that omits Version; partially installed packages.","solutions":["Check the PKG-INFO file at the reported path for a 'Version:' header and add it if missing.","Reinstall the package to regenerate complete metadata.","If constructing Distribution manually, pass version explicitly to the constructor.","Verify the metadata directory (egg-info/dist-info) is not truncated or empty."],"exampleFix":"// before: PKG-INFO missing Version line\n// Metadata-Version: 2.1\n// Name: mypackage\n// (no Version: header)\n\n// after\n// Metadata-Version: 2.1\n// Name: mypackage\n// Version: 1.0.0","handlingStrategy":"validation","validationCode":"def has_version_in_metadata(dist) -> bool:\n    try:\n        _ = dist.version\n        return True\n    except ValueError:\n        return False","typeGuard":"def distribution_has_version(dist) -> bool:\n    try:\n        v = dist._version\n        return True\n    except AttributeError:\n        try:\n            from pkg_resources import _version_from_file\n            lines = dist._get_metadata(dist.PKG_INFO)\n            return _version_from_file(lines) is not None\n        except Exception:\n            return False\n","tryCatchPattern":"try:\n    version = dist.version\nexcept ValueError:\n    version = 'unknown'\n    # log: PKG-INFO missing Version header at {path}","preventionTips":["Ensure PKG-INFO always contains a 'Version:' header.","Pass version explicitly when constructing Distribution objects.","Reinstall packages with corrupt or incomplete egg-info/dist-info directories."],"tags":["metadata","pkg-resources","version","distribution"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}