# 错误：由于 OSError 无法安装包：[Errno 28] 设备上没有剩余空间

- **ID:** `python/pip-no-space-left-on-device`
- **领域:** python
- **类别:** system_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

承载 pip 缓存或目标 site-packages 的文件系统空间已耗尽，通常是由于 ~/.cache/pip 中积累了大量 wheel 下载。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.8 | active | — | — |
| 3.9 | active | — | — |
| 3.10 | active | — | — |
| 3.11 | active | — | — |
| 3.12 | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   pip cache purge
# or manually
rm -rf ~/.cache/pip
df -h ~
pip install somepkg
   ```
2. **** (90% 成功率)
   ```
   export PIP_CACHE_DIR=/mnt/bigdisk/pip-cache
pip install somepkg
# or persist it
pip config set global.cache-dir /mnt/bigdisk/pip-cache
   ```

## 无效尝试

- **** — Avoids new cache writes but the target site-packages still needs space and may be on the same full volume. (70% 失败率)
- **** — Upgrading pip itself needs space and does not free any. (90% 失败率)
