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

其他格式: JSON · Markdown 中文 · English
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.

generic

解决方案

  1. 95% 成功率
    Install to user site-packages: pip install --user <package>.
  2. 98% 成功率
    Create and use a virtual environment: python -m venv myenv && source myenv/bin/activate && pip install <package>.

无效尝试

常见但无效的做法:

  1. 70% 失败

    Using sudo can install packages as root, causing permission issues later and potentially breaking the system Python environment.

  2. 85% 失败

    Creates security risks and may still fail if the directory is immutable or on a read-only filesystem.