{
  "id": "python/pip-error-externally-managed-environment",
  "signature": "error: externally-managed-environment\n\n× This environment is externally managed\n╰─> To install Python packages system-wide, try apt install python3-xyz, where xyz is the package you are trying to install.",
  "signature_zh": "错误：externally-managed-environment（环境由外部管理）\n此环境由外部管理，无法直接安装系统级 Python 包。",
  "regex": "error:\\ externally\\-managed\\-environment\\\n\\\n×\\ This\\ environment\\ is\\ externally\\ managed\\\n╰─>\\ To\\ install\\ Python\\ packages\\ system\\-wide,\\ try\\ apt\\ install\\ python3\\-xyz,\\ where\\ xyz\\ is\\ the\\ package\\ you\\ are\\ trying\\ to\\ install\\.",
  "domain": "python",
  "category": "install_error",
  "subcategory": null,
  "root_cause": "PEP 668: Debian/Ubuntu (and Fedora) mark the system Python with an `EXTERNALLY-MANAGED` marker file so pip refuses to install into it, preventing breakage of OS-managed packages.",
  "root_cause_type": "generic",
  "root_cause_zh": "PEP 668：Debian/Ubuntu（及 Fedora）在系统 Python 中放置 `EXTERNALLY-MANAGED` 标记文件，使 pip 拒绝安装到系统环境，防止破坏操作系统管理的包。",
  "versions": [
    {
      "version": "3.11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.12",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.13",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "It works but writes into the OS-managed site-packages; a later apt upgrade can overwrite or break the package, and vice versa. Frequently corrupts the system Python.",
      "fail_rate": 0.65,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Removing the marker bypasses the guard but does not solve the underlying problem; the next apt upgrade reinstalls the marker and can clobber your packages.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "Create and use a virtual environment (the intended workflow):\n\npython3 -m venv .venv\nsource .venv/bin/activate\npip install <pkg>",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Install via the OS package manager when a distro package exists:\n\nsudo apt install python3-requests\n\nFor user-level installs without venv, use pipx for applications or `pip install --user` after creating a venv.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.9,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-05-11",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}