{"record":{"id":"c6f6e1e20c4bb11b","repo":"pypa/pip","slug":"no-metadata-except-pkg-info-is-available","errorCode":null,"errorMessage":"No metadata except PKG-INFO is available","messagePattern":"No metadata except PKG-INFO is available","errorType":"exception","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/pkg_resources/__init__.py","lineNumber":2171,"sourceCode":"        metadata = FileMetadata(\"/path/to/PKG-INFO\")\n\n    This provider rejects all data and metadata requests except for PKG-INFO,\n    which is treated as existing, and will be the contents of the file at\n    the provided location.\n    \"\"\"\n\n    def __init__(self, path: StrPath):\n        self.path = path\n\n    def _get_metadata_path(self, name):\n        return self.path\n\n    def has_metadata(self, name: str) -> bool:\n        return name == 'PKG-INFO' and os.path.isfile(self.path)\n\n    def get_metadata(self, name: str):\n        if name != 'PKG-INFO':\n            raise KeyError(\"No metadata except PKG-INFO is available\")\n\n        with open(self.path, encoding='utf-8', errors=\"replace\") as f:\n            metadata = f.read()\n        self._warn_on_replacement(metadata)\n        return metadata\n\n    def _warn_on_replacement(self, metadata):\n        replacement_char = '�'\n        if replacement_char in metadata:\n            tmpl = \"{self.path} could not be properly decoded in UTF-8\"\n            msg = tmpl.format(**locals())\n            warnings.warn(msg)\n\n    def get_metadata_lines(self, name: str) -> Iterator[str]:\n        return yield_lines(self.get_metadata(name))\n\n\nclass PathMetadata(DefaultProvider):","sourceCodeStart":2153,"sourceCodeEnd":2189,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_vendor/pkg_resources/__init__.py#L2153-L2189","documentation":"Raised by FileMetadata.get_metadata when any metadata name other than 'PKG-INFO' is requested. FileMetadata is a minimal provider that wraps a single PKG-INFO file path and deliberately rejects all other metadata requests (entry_points.txt, requires.txt, etc.) with a KeyError. This is by design — FileMetadata only knows about one file.","triggerScenarios":"Calling get_metadata('requires.txt') or any non-PKG-INFO name on a Distribution whose provider is a FileMetadata instance. FileMetadata is constructed with a single file path (e.g. `FileMetadata('/path/to/PKG-INFO')`) and only returns data for 'PKG-INFO'.","commonSituations":"Manually constructing a Distribution with FileMetadata pointing at a lone PKG-INFO file and then calling get_entry_map() or requires(), which internally request other metadata files; tooling that inspects metadata on a partially-extracted or incomplete package.","solutions":["Use PathMetadata or EggMetadata instead of FileMetadata — they support the full set of metadata files in an egg-info/dist-info directory.","If you only need PKG-INFO data, always request 'PKG-INFO' specifically.","Wrap calls in try/except KeyError when querying metadata from an unknown provider type.","Point the metadata provider at the full egg-info or dist-info directory rather than a single PKG-INFO file."],"exampleFix":"// before\nfrom pkg_resources import FileMetadata, Distribution\nmd = FileMetadata('/path/to/PKG-INFO')\ndist = Distribution(metadata=md)\ndist.get_entry_map()  # KeyError: No metadata except PKG-INFO\n\n// after\nfrom pkg_resources import PathMetadata, Distribution\negg_info = '/path/to/Package.egg-info'\nmd = PathMetadata('/path/to', egg_info)\ndist = Distribution.from_location('/path/to', 'Package.egg-info', metadata=md)\ndist.get_entry_map()  # works","handlingStrategy":"try-catch","validationCode":"from pkg_resources import FileMetadata\nmd = dist._provider if hasattr(dist, '_provider') else None\nif isinstance(md, FileMetadata):\n    # only PKG-INFO is available; avoid other metadata calls\n    pass","typeGuard":"from pkg_resources import FileMetadata\ndef supports_full_metadata(provider) -> bool:\n    return not isinstance(provider, FileMetadata)\n","tryCatchPattern":"try:\n    dist.get_entry_map()\nexcept KeyError:\n    # FileMetadata or incomplete provider; skip entry point inspection\n    entry_map = {}\n","preventionTips":["Use PathMetadata with a full egg-info/dist-info directory instead of FileMetadata.","Always check provider type before querying non-PKG-INFO metadata.","Construct Distribution.from_location() rather than manually wiring FileMetadata."],"tags":["metadata","pkg-resources","file-provider","keyerror"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}