python system_error ai_generated true

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

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active — — —

Root Cause

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

generic

中文

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

Workarounds

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

Dead Ends

Common approaches that don't work:

  1. 50% fail

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

  2. 95% fail

    Reinstalling Python does not change directory ownership.

  3. 40% fail

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