# 警告：目录 '/home/user/.cache/pip' 或其父目录不属于当前用户或不可写。缓存已被禁用。

- **ID:** `python/pip-cache-directory-not-writable`
- **领域:** python
- **类别:** system_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

pip 缓存目录由其他用户（通常是之前 sudo pip 运行的 root）创建，或权限受限，因此 pip 无法写入并禁用缓存。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **** (92% 成功率)
   ```
   Reclaim ownership: sudo chown -R $USER:$USER ~/.cache/pip
   ```
2. **** (85% 成功率)
   ```
   Point the cache elsewhere: pip config set global.cache-dir ~/.cache/pip-user  # or export PIP_CACHE_DIR=~/.cache/pip-user
   ```

## 无效尝试

- **** — Silences the warning by skipping cache entirely but leaves the root-owned directory in place; every future install re-warns. (50% 失败率)
- **** — Makes root the owner again, guaranteeing the non-root user still cannot write; the warning persists. (90% 失败率)
