python config_error ai_generated true

error: externally-managed-environment × This environment is externally managed ╰─> To install Python packages system-wide, try apt install python3-xyz...

ID: python/pip-externally-managed-environment

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active — — —

Root Cause

PEP 668 marker file EXTERNALLY-MANAGED prevents pip from modifying the system Python environment.

generic

中文

PEP 668 标记文件 EXTERNALLY-MANAGED 阻止 pip 修改系统 Python 环境。

Workarounds

  1. 99% success
    `python3 -m venv venv && source venv/bin/activate && pip install foo`.
  2. 95% success
    `pipx install foo` isolates the tool in its own venv.

Dead Ends

Common approaches that don't work:

  1. 30% fail

    Works but risks breaking distro-managed packages; not recommended for production.

  2. 90% fail

    Still blocked by the PEP 668 marker and can corrupt system Python.