{
  "id": "python/matplotlib-agg-pillow-missing",
  "signature": "ImportError: cannot import name '_imaging' from 'PIL' (PIL is required for image saving)",
  "signature_zh": "ImportError: 无法从 'PIL' 导入名称 '_imaging'（保存图像需要 PIL）。",
  "regex": "ImportError:\\ cannot\\ import\\ name\\ '_imaging'\\ from\\ 'PIL'\\ \\(PIL\\ is\\ required\\ for\\ image\\ saving\\)",
  "domain": "python",
  "category": "install_error",
  "subcategory": null,
  "root_cause": "Pillow is not installed or a broken partial install exists, so matplotlib cannot save PNG/JPEG via the Agg backend.",
  "root_cause_type": "generic",
  "root_cause_zh": "未安装 Pillow 或存在损坏的部分安装，导致 matplotlib 无法通过 Agg 后端保存 PNG/JPEG。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The 'PIL' package on PyPI is a stub that raises an error; the correct package is Pillow.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Import order does not fix a broken _imaging C extension.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.94,
      "how": "pip uninstall -y PIL Pillow\npip install --no-cache-dir Pillow",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "fig.savefig('out.pdf')  # or 'out.svg'",
      "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-03-30",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}