{
  "id": "python/matplotlib-agg-backend-missing",
  "signature": "ImportError: Cannot load backend 'TkAgg' which requires the 'tkinter' interactive framework, as 'headless' is not running a display.",
  "signature_zh": "ImportError: 无法加载需要'tkinter'交互框架的后端'TkAgg'，因为'headless'未运行显示。",
  "regex": "ImportError:\\ Cannot\\ load\\ backend\\ 'TkAgg'\\ which\\ requires\\ the\\ 'tkinter'\\ interactive\\ framework,\\ as\\ 'headless'\\ is\\ not\\ running\\ a\\ display\\.",
  "domain": "python",
  "category": "module_error",
  "subcategory": null,
  "root_cause": "Running matplotlib on a headless server without a display, but the default backend (TkAgg) requires a graphical environment.",
  "root_cause_type": "generic",
  "root_cause_zh": "在无显示服务器上运行matplotlib，但默认后端(TkAgg)需要图形环境。",
  "versions": [
    {
      "version": "3.7",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Installing tkinter via pip",
      "why_fails": "tkinter is part of the standard library and cannot be installed via pip; the issue is the missing display, not the module.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "Setting backend after importing pyplot",
      "why_fails": "The backend must be set before importing pyplot; setting it after has no effect.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Set the Agg backend before importing matplotlib.pyplot",
      "success_rate": 0.95,
      "how": "import matplotlib; matplotlib.use('Agg'); import matplotlib.pyplot as plt",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use the 'pdf' or 'svg' backend for file output",
      "success_rate": 0.9,
      "how": "import matplotlib; matplotlib.use('PDF'); import matplotlib.pyplot as plt",
      "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.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-01-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}