python install_error ai_generated true

error: externally-managed-environment × This environment is externally managed ╰─> To install Python packages system-wide, try apt install python3-xyz, where xyz is the package you are trying to install.

ID: python/pip-externally-managed-environment

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

PEP 668 marker file (EXTERNALLY-MANAGED) exists in the system Python's stdlib, telling pip not to modify the OS-managed interpreter.

generic

中文

PEP 668 标记文件(EXTERNALLY-MANAGED)存在于系统 Python 的 stdlib 中,告诉 pip 不要修改操作系统管理的解释器。

Workarounds

  1. 98% success
    python3 -m venv .venv
    source .venv/bin/activate
    python -m pip install requests
  2. 92% success
    sudo apt install python3-requests
    # or for CLI apps
    pipx install ruff

Dead Ends

Common approaches that don't work:

  1. 90% fail

    --user still writes into the externally-managed interpreter's user site-packages and is blocked.

  2. 95% fail

    Running as root does not bypass the PEP 668 marker and can corrupt OS packages.