pip environment ai_generated true

error: externally-managed-environment

ID: pip/externally-managed-environment

Also available as: JSON · Markdown
97%Fix Rate
98%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
23 active
24 active

Root Cause

PEP 668: pip refuses to install into system Python because the OS package manager manages it.

generic

Workarounds

  1. 98% success Use a virtual environment: python -m venv .venv && source .venv/bin/activate
    Virtual environments are isolated and don't conflict with system Python

    Sources: https://docs.python.org/3/library/venv.html

  2. 93% success Use pipx for CLI tools: pipx install <tool>
    # Install pipx:
    python -m pip install --user pipx
    python -m pipx ensurepath
    
    # Install CLI tools with pipx (each gets its own venv):
    pipx install black
    pipx install ruff
    pipx install httpie

Dead Ends

Common approaches that don't work:

  1. Removing the EXTERNALLY-MANAGED file 85% fail

    Breaks OS package manager integration; system packages may conflict

  2. Using --break-system-packages flag 75% fail

    Bypasses the protection; can corrupt system Python

Error Chain

Frequently confused with: