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'

ID: python/pip-permission-denied-install

Also available as: JSON · Markdown · 中文
80%Fix Rate
90%Confidence
0Evidence
2024-03-30First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.8 active — — —
3.9 active — — —
3.10 active — — —
3.11 active — — —
3.12 active — — —

Root Cause

pip is trying to install into a system directory without sufficient permissions.

generic

中文

pip 试图在没有足够权限的情况下安装到系统目录。

Workarounds

  1. 95% success
    Create and activate a virtual environment: `python -m venv venv && source venv/bin/activate && pip install foo`.
  2. 80% success
    If you must install globally, use `pip install --user foo`.

Dead Ends

Common approaches that don't work:

  1. 30% fail

    May work but can cause conflicts; better to use a virtual environment.

  2. 60% fail

    Can break system packages and is discouraged.