# ImportError: 无法从'matplotlib'导入名称'cm'（未知位置）

- **ID:** `python/matplotlib-missing-colormap-module`
- **领域:** python
- **类别:** module_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

matplotlib安装损坏或不完整，导致cm模块缺失，或存在名为matplotlib.py的本地文件造成命名冲突。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.7 | active | — | — |
| 3.8 | active | — | — |

## 解决方案

1. **Check for local matplotlib.py file and rename it** (85% 成功率)
   ```
   import sys; print([p for p in sys.path if 'matplotlib.py' in p])
   ```
2. **Perform a clean reinstall in a new virtual environment** (95% 成功率)
   ```
   python -m venv newenv; source newenv/bin/activate; pip install matplotlib
   ```

## 无效尝试

- **Reinstalling matplotlib with pip install --upgrade matplotlib** — If the issue is a local file conflict, reinstallation may not help. (60% 失败率)
- **Importing matplotlib.cm instead of from matplotlib import cm** — Both should work; if cm is missing, both fail. (90% 失败率)
