{"record":{"id":"02ca0dd7105eabd7","repo":"pypa/pip","slug":"could-not-read-path-r-file-e-r","errorCode":null,"errorMessage":"could not read {path!r} file: {e!r}","messagePattern":"could not read (.+?) file: (.+?)","errorType":"exception","errorClass":"UnsupportedWheel","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/utils/wheel.py","lineNumber":73,"sourceCode":"    info_dir = info_dirs[0]\n\n    info_dir_name = canonicalize_name(info_dir)\n    canonical_name = canonicalize_name(name)\n    if not info_dir_name.startswith(canonical_name):\n        raise UnsupportedWheel(\n            f\".dist-info directory {info_dir!r} does not start with {canonical_name!r}\"\n        )\n\n    return info_dir\n\n\ndef read_wheel_metadata_file(source: ZipFile, path: str) -> bytes:\n    try:\n        return source.read(path)\n        # BadZipFile for general corruption, KeyError for missing entry,\n        # and RuntimeError for password-protected files\n    except (BadZipFile, KeyError, RuntimeError) as e:\n        raise UnsupportedWheel(f\"could not read {path!r} file: {e!r}\")\n\n\ndef wheel_metadata(source: ZipFile, dist_info_dir: str) -> Message:\n    \"\"\"Return the WHEEL metadata of an extracted wheel, if possible.\n    Otherwise, raise UnsupportedWheel.\n    \"\"\"\n    path = f\"{dist_info_dir}/WHEEL\"\n    # Zip file path separators must be /\n    wheel_contents = read_wheel_metadata_file(source, path)\n\n    try:\n        wheel_text = wheel_contents.decode()\n    except UnicodeDecodeError as e:\n        raise UnsupportedWheel(f\"error decoding {path!r}: {e!r}\")\n\n    # FeedParser (used by Parser) does not raise any exceptions. The returned\n    # message may have .defects populated, but for backwards-compatibility we\n    # currently ignore them.","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/utils/wheel.py#L55-L91","documentation":"Raised by read_wheel_metadata_file() when reading a file from the wheel zip raises BadZipFile (general corruption), KeyError (entry missing), or RuntimeError (password-protected zip). It indicates the wheel's internal metadata file could not be read from the archive.","triggerScenarios":"Calling read_wheel_metadata_file(source, path) where source.read(path) fails. Reached when pip reads the WHEEL or METADATA file from the .dist-info directory during wheel installation via parse_wheel().","commonSituations":"A truncated or corrupt wheel download (BadZipFile). A wheel built without the expected metadata file (KeyError). A password-protected zip mislabeled as a wheel (RuntimeError). Disk corruption or an interrupted download cached by pip.","solutions":["Clear pip's cache: 'pip cache purge', then reinstall","Verify the wheel integrity: 'unzip -t <file>.whl'","Re-download the wheel from the official PyPI index","Rebuild the wheel with 'python -m build --wheel'","Check for a password-protected zip and rebuild without a password"],"exampleFix":"// before\npip install ./possibly-corrupt-1.0-py3-none-any.whl\n// after\npip cache purge\nunzip -t possibly-corrupt-1.0-py3-none-any.whl\n# if the test fails, re-download or rebuild\npip install --force-reinstall possibly-corrupt==1.0","handlingStrategy":"validation","validationCode":"import zipfile\n\ndef wheel_files_are_readable(path: str) -> bool:\n    try:\n        with zipfile.ZipFile(path) as zf:\n            for name in zf.namelist():\n                if name.endswith('.dist-info/WHEEL'):\n                    zf.read(name)\n                    return True\n            return False\n    except (zipfile.BadZipFile, KeyError, RuntimeError):\n        return False","typeGuard":"import zipfile\n\ndef is_intact_wheel_zip(path: str) -> bool:\n    try:\n        with zipfile.ZipFile(path) as zf:\n            zf.testzip()  # returns None if OK\n            return True\n    except (zipfile.BadZipFile, RuntimeError):\n        return False","tryCatchPattern":"from pip._internal.exceptions import UnsupportedWheel\n\ntry:\n    read_wheel_metadata_file(wheel_zip, path)\nexcept UnsupportedWheel as e:\n    if 'could not read' in str(e):\n        # re-download or rebuild the wheel\n        raise PackagingError(f'wheel metadata unreadable, re-download: {e}')\n    raise","preventionTips":["Verify zip integrity with 'unzip -t <file>.whl' before installing","Clear pip cache ('pip cache purge') to remove corrupt cached downloads","Do not password-protect wheel zips","Re-download from the official index"],"tags":["wheel","zipfile","corruption","metadata","installation"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}