{"record":{"id":"cda59a7c56353c28","repo":"pypa/pip","slug":"error-decoding-metadata-for-self-wheel-name-e","errorCode":null,"errorMessage":"Error decoding metadata for {self._wheel_name}: {e} in {name} file","messagePattern":"Error decoding metadata for (.+?): (.+?) in (.+?) file","errorType":"exception","errorClass":"UnsupportedWheel","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/metadata/pkg_resources.py","lineNumber":68,"sourceCode":"class InMemoryMetadata:\n    \"\"\"IMetadataProvider that reads metadata files from a dictionary.\n\n    This also maps metadata decoding exceptions to our internal exception type.\n    \"\"\"\n\n    def __init__(self, metadata: Mapping[str, bytes], wheel_name: str) -> None:\n        self._metadata = metadata\n        self._wheel_name = wheel_name\n\n    def has_metadata(self, name: str) -> bool:\n        return name in self._metadata\n\n    def get_metadata(self, name: str) -> str:\n        try:\n            return self._metadata[name].decode()\n        except UnicodeDecodeError as e:\n            # Augment the default error with the origin of the file.\n            raise UnsupportedWheel(\n                f\"Error decoding metadata for {self._wheel_name}: {e} in {name} file\"\n            )\n\n    def get_metadata_lines(self, name: str) -> Iterable[str]:\n        return pkg_resources.yield_lines(self.get_metadata(name))\n\n    def metadata_isdir(self, name: str) -> bool:\n        return False\n\n    def metadata_listdir(self, name: str) -> list[str]:\n        return []\n\n    def run_script(self, script_name: str, namespace: str) -> None:\n        pass\n\n\nclass Distribution(BaseDistribution):\n    def __init__(self, dist: pkg_resources.Distribution) -> None:","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/metadata/pkg_resources.py#L50-L86","documentation":"Raised as UnsupportedWheel from InMemoryMetadata.get_metadata in pkg_resources.py:63-70. When decoding a metadata file stored in the in-memory dict for a wheel, a UnicodeDecodeError on .decode() is wrapped with the wheel name and file name, because non-UTF-8 metadata in a wheel is unsupported.","triggerScenarios":"Distribution.from_wheel reads wheel metadata via read_wheel_metadata_file into InMemoryMetadata; later get_metadata(name) calls .decode() on the bytes and raises UnicodeDecodeError, re-raised as UnsupportedWheel.","commonSituations":"A wheel containing metadata files encoded in a non-UTF-8 charset; a corrupted wheel whose metadata bytes are not valid UTF-8; a build tool that wrote non-UTF-8 text into METADATA.","solutions":["Use a different wheel/source whose metadata is UTF-8.","Rebuild the wheel ensuring all metadata files are UTF-8 encoded.","If the package is yours, fix the source of the non-UTF-8 content."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Before reading in-memory wheel metadata, confirm UTF-8 decode:\nfor name, data in metadata_dict.items():\n    data.decode('utf-8')  # raises early if a file is not UTF-8","typeGuard":null,"tryCatchPattern":"from pip._internal.exceptions import UnsupportedWheel\ntry:\n    meta = in_memory.get_metadata('METADATA')\nexcept UnsupportedWheel as e:\n    if 'Error decoding metadata' in str(e):\n        # use an alternative wheel / rebuild\n        ...","preventionTips":["Encode all wheel metadata as UTF-8.","Run twine check / auditwheel before publishing wheels.","Avoid non-UTF-8 content in any text metadata field."],"tags":["metadata","wheel","encoding","pkg-resources"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}