python system_error ai_generated true

错误:异常: 回溯(最近的调用最后): File "...",第 1 行,在 <module> 中 PermissionError: [Errno 13] 权限被拒绝:'/usr/lib/python3.11/site-packages/foo/__init__.py'

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

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

版本兼容性

版本状态引入弃用备注
3.x active

根因分析

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

English

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

generic

解决方案

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

无效尝试

常见但无效的做法:

  1. 85% 失败

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

  2. 70% 失败

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