python system_error ai_generated true

错误:由于 OSError 无法安装包:[Errno 13] 权限被拒绝:'/usr/local/lib/python3.11/site-packages/foo' 请考虑使用 `--user` 选项或检查权限。

ERROR: Could not install packages due to an OSError: [Errno 13] Permission denied: '/usr/local/lib/python3.11/site-packages/foo' Consider using the `--user` option or check the permissions.

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

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

版本兼容性

版本状态引入弃用备注
3.8 active
3.9 active
3.10 active
3.11 active
3.12 active

根因分析

pip 正在写入当前用户无权限修改的系统级 site-packages,通常因为该解释器由 root 拥有。

English

pip is writing to a system-wide site-packages that the current user cannot modify, usually because the interpreter is owned by root.

generic

解决方案

  1. 85% 成功率
    Install for the current user: `pip install --user foo`, then ensure `~/.local/bin` is on PATH.
  2. 95% 成功率
    Use a virtual environment: `python -m venv .venv && source .venv/bin/activate && pip install foo`.

无效尝试

常见但无效的做法:

  1. 40% 失败

    Installs system-wide, can break OS packages, and pollutes root's environment.

  2. 70% 失败

    Security risk and may be reset by package manager upgrades.