{
  "id": "python/matplotlib-missing-colormap-module",
  "signature": "ImportError: cannot import name 'cm' from 'matplotlib' (unknown location)",
  "signature_zh": "ImportError: 无法从'matplotlib'导入名称'cm'（未知位置）",
  "regex": "ImportError:\\ cannot\\ import\\ name\\ 'cm'\\ from\\ 'matplotlib'\\ \\(unknown\\ location\\)",
  "domain": "python",
  "category": "module_error",
  "subcategory": null,
  "root_cause": "A corrupted or partial installation of matplotlib where the cm module is missing, or a naming conflict with a local file named matplotlib.py.",
  "root_cause_type": "generic",
  "root_cause_zh": "matplotlib安装损坏或不完整，导致cm模块缺失，或存在名为matplotlib.py的本地文件造成命名冲突。",
  "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": "Reinstalling matplotlib with pip install --upgrade matplotlib",
      "why_fails": "If the issue is a local file conflict, reinstallation may not help.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "Importing matplotlib.cm instead of from matplotlib import cm",
      "why_fails": "Both should work; if cm is missing, both fail.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Check for local matplotlib.py file and rename it",
      "success_rate": 0.85,
      "how": "import sys; print([p for p in sys.path if 'matplotlib.py' in p])",
      "condition": "",
      "sources": []
    },
    {
      "action": "Perform a clean reinstall in a new virtual environment",
      "success_rate": 0.95,
      "how": "python -m venv newenv; source newenv/bin/activate; pip install matplotlib",
      "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.82,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-02-28",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}