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

- **ID:** `pip/cache-corruption-json-decode-error`
- **领域:** pip
- **类别:** data_error
- **错误码:** `ERROR`
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| pip 23.0 | active | — | — |
| pip 23.1 | active | — | — |
| pip 23.2 | active | — | — |
| pip 24.0 | active | — | — |

## 解决方案

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
   ```

## 无效尝试

- **Manually editing the cache JSON file to fix the corruption** — The cache file is often binary or partially written; manual editing is unreliable and may introduce further corruption. (95% 失败率)
- **Using pip install --no-cache-dir once but expecting the cache to be automatically repaired** — --no-cache-dir bypasses the cache for the current install but does not remove the corrupted entry; subsequent pip commands will still fail. (80% 失败率)
- **Deleting only the specific cache file without understanding the cache directory structure** — The cache may have multiple corrupted entries across different packages; a targeted delete may miss some. (60% 失败率)
