python system_error ai_generated true

错误:由于 OSError:[Errno 13] 权限被拒绝:'/usr/local/lib/python3.9/site-packages/package',无法安装包

ERROR: Could not install packages due to an OSError: [Errno 13] Permission denied: '/usr/local/lib/python3.9/site-packages/package'

ID: python/pip-install-error-permission-denied

其他格式: JSON · Markdown 中文 · English
80%修复率
87%置信度
0证据数
2024-08-30首次发现

版本兼容性

版本状态引入弃用备注
3.x active — — —

根因分析

pip 缺少对目标 site-packages 目录的写入权限,通常是因为该目录属于 root 或其他用户。

English

pip lacks write permissions to the target site-packages directory, typically because it is owned by root or another user.

generic

解决方案

  1. 90% 成功率
    pip install --user package
  2. 98% 成功率
    python3 -m venv myenv && source myenv/bin/activate && pip install package
  3. 70% 成功率
    sudo chown -R $USER /usr/local/lib/python3.9/site-packages

无效尝试

常见但无效的做法:

  1. 50% 失败

    This can work but may cause permission issues later and is not recommended for user environments.

  2. 95% 失败

    Reinstalling Python does not change directory ownership.

  3. 40% 失败

    This may work but can lead to conflicts with system packages.