# ImportError: 无法加载后端 'TkAgg'，它需要 'tk' 交互框架，而当前运行的是 'headless'。

- **ID:** `python/matplotlib-tkinter-not-available`
- **领域:** python
- **类别:** module_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

matplotlib 被配置为使用 TkAgg，但环境未安装 Tk 或处于无头状态（无 DISPLAY）。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   export MPLBACKEND=Agg
python your_script.py
   ```
2. **** (82% 成功率)
   ```
   sudo apt-get install -y python3-tk tk-dev
# then run under a real X session or Xvfb:
xvfb-run -a python your_script.py
   ```

## 无效尝试

- **** — There is no such PyPI package; tkinter ships with the Python interpreter and needs the OS tk-dev package. (95% 失败率)
- **** — Reinforces the broken backend choice and fails again at import. (90% 失败率)
