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-pep668

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.10 active — — —
3.11 active — — —
3.12 active — — —

Root Cause

PEP 668 marks the system Python as externally managed via an EXTERNALLY-MANAGED marker file. Debian/Ubuntu and Homebrew ship this to prevent pip from breaking the OS package manager.

generic

中文

PEP 668 通过 EXTERNALLY-MANAGED 标记文件将系统 Python 标记为外部管理。Debian/Ubuntu 和 Homebrew 附带此文件,以防止 pip 破坏操作系统包管理器。

Workarounds

  1. 98% success
    python3 -m venv .venv && source .venv/bin/activate && pip install package
  2. 95% success
    pipx install some-cli-tool
  3. 90% success
    pip install --break-system-packages package

Dead Ends

Common approaches that don't work:

  1. 95% fail

    Running as root does not bypass the marker; pip still refuses.

  2. 40% fail

    Works but breaks the OS package manager's invariants and is reverted on the next apt upgrade.