# 错误：由于操作系统错误 [Errno 30] 只读文件系统，无法安装软件包

- **ID:** `pip/cache-read-only-filesystem`
- **领域:** pip
- **类别:** system_error
- **错误码:** `ERROR`
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

pip 的缓存目录位于只读文件系统上（例如在容器、CI 环境或具有只读权限的挂载卷中），阻止 pip 写入或更新缓存文件。

## 版本兼容性

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

## 解决方案

1. ```
   完全禁用 pip 的缓存：pip install --no-cache-dir <package>
   ```
2. ```
   将 PIP_CACHE_DIR 环境变量设置为可写位置：export PIP_CACHE_DIR=/tmp/pip-cache && pip install <package>
   ```

## 无效尝试

- **Run pip with sudo or as root to override permissions** — The filesystem is genuinely read-only (e.g., mounted with -o ro); root cannot write to a read-only filesystem either. This often happens in Docker containers where the volume is mounted read-only. (90% 失败率)
- **Delete the cache directory manually with rm -rf /root/.cache/pip** — Deletion also requires write permission to the filesystem; the same read-only restriction applies. (95% 失败率)
