python system_error ai_generated true

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

Also available as: JSON · Markdown · 中文
80%Fix Rate
89%Confidence
0Evidence
2024-02-14First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.8 active
3.9 active
3.10 active
3.11 active
3.12 active

Root Cause

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

generic

中文

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

Workarounds

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

Dead Ends

Common approaches that don't work:

  1. 40% fail

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

  2. 70% fail

    Security risk and may be reset by package manager upgrades.