ERROR pip data_error ai_generated true

错误:异常:回溯(最近一次调用最后):... json.decoder.JSONDecodeError:期望值:第 1 行第 1 列(字符 0)。'https://pypi.org/simple/package/' 的缓存条目已损坏。尝试使用 'pip cache purge' 删除缓存。

ERROR: Exception: Traceback (most recent call last): ... json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0). The cache entry for 'https://pypi.org/simple/package/' is corrupted. Try deleting the cache with 'pip cache purge'.

ID: pip/cache-corruption-json-decode-error

其他格式: JSON · Markdown 中文 · English
95%修复率
90%置信度
1证据数
2023-07-22首次发现

版本兼容性

版本状态引入弃用备注
pip 23.0 active
pip 23.1 active
pip 23.2 active
pip 24.0 active

根因分析

软件包索引的 pip HTTP 缓存存在损坏的 JSON 文件,可能是由于下载中断或磁盘写入错误导致,使 pip 在解析缓存的响应时失败。

English

The pip HTTP cache for the package index has a corrupted JSON file, likely due to an interrupted download or disk write error, causing pip to fail when parsing the cached response.

generic

官方文档

https://pip.pypa.io/en/stable/topics/caching/

解决方案

  1. 清除整个 pip HTTP 缓存:pip cache purge。然后重试安装。这将删除所有缓存的软件包索引响应。
  2. 如果 pip cache purge 因权限问题失败,请手动删除缓存目录:rm -rf ~/.cache/pip(Linux/macOS)或 rmdir /s %LocalAppData%\pip\cache(Windows)。然后重试。
  3. 使用 pip install --no-cache-dir 作为临时解决方法,完全绕过缓存:pip install --no-cache-dir package

无效尝试

常见但无效的做法:

  1. Manually editing the cache JSON file to fix the corruption 95% 失败

    The cache file is often binary or partially written; manual editing is unreliable and may introduce further corruption.

  2. Using pip install --no-cache-dir once but expecting the cache to be automatically repaired 80% 失败

    --no-cache-dir bypasses the cache for the current install but does not remove the corrupted entry; subsequent pip commands will still fail.

  3. Deleting only the specific cache file without understanding the cache directory structure 60% 失败

    The cache may have multiple corrupted entries across different packages; a targeted delete may miss some.