python
system_error
ai_generated
true
错误:由于 OSError 无法安装包:[Errno 13] 权限被拒绝:'/usr/local/lib/python3.10/site-packages/...'
ERROR: Could not install packages due to an OSError: [Errno 13] Permission denied: '/usr/local/lib/python3.10/site-packages/...'
ID: python/pip-permission-denied-system-site-packages
80%修复率
89%置信度
0证据数
2024-01-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.7 | active | — | — | — |
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
根因分析
pip 试图安装到系统级的 site-packages 目录,但没有足够的写入权限。这通常发生在未使用 sudo 运行 pip 或目录属于 root 用户时。
English
pip is attempting to install into the system-wide site-packages directory without sufficient write permissions. This occurs when running pip without sudo on a system Python or when the directory is owned by root.
解决方案
-
95% 成功率
Install to user site-packages: pip install --user <package>.
-
98% 成功率
Create and use a virtual environment: python -m venv myenv && source myenv/bin/activate && pip install <package>.
无效尝试
常见但无效的做法:
-
70% 失败
Using sudo can install packages as root, causing permission issues later and potentially breaking the system Python environment.
-
85% 失败
Creates security risks and may still fail if the directory is immutable or on a read-only filesystem.