python system_error ai_generated true

ERROR: Exception: Traceback (most recent call last): File "...", line 1, in <module> PermissionError: [Errno 13] Permission denied: '/usr/lib/python3.11/site-packages/foo/__init__.py'

ID: python/pip-uninstall-permission-denied

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

pip is trying to modify a site-packages directory owned by root (or another user), but the current user lacks write permission.

generic

中文

pip 尝试修改由 root(或其他用户)拥有的 site-packages 目录,但当前用户缺少写权限。

Workarounds

  1. 98% success
    python3 -m venv ~/.venvs/app
    source ~/.venvs/app/bin/activate
    python -m pip install foo
  2. 90% success
    python -m pip install --user --force-reinstall foo
    # ensure ~/.local/bin is on PATH
    export PATH="$HOME/.local/bin:$PATH"

Dead Ends

Common approaches that don't work:

  1. 85% fail

    Weakens system security and can break imports for other users; does not address the real fix.

  2. 70% fail

    Leaves the old root-owned copy in place, causing import shadowing and version confusion.