python
install_error
ai_generated
true
ImportError: 无法从 'PIL' 导入名称 '_imaging'(保存图像需要 PIL)。
ImportError: cannot import name '_imaging' from 'PIL' (PIL is required for image saving)
ID: python/matplotlib-agg-pillow-missing
80%修复率
88%置信度
0证据数
2024-03-30首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
未安装 Pillow 或存在损坏的部分安装,导致 matplotlib 无法通过 Agg 后端保存 PNG/JPEG。
English
Pillow is not installed or a broken partial install exists, so matplotlib cannot save PNG/JPEG via the Agg backend.
解决方案
-
94% 成功率
pip uninstall -y PIL Pillow pip install --no-cache-dir Pillow
-
90% 成功率
fig.savefig('out.pdf') # or 'out.svg'
无效尝试
常见但无效的做法:
-
95% 失败
The 'PIL' package on PyPI is a stub that raises an error; the correct package is Pillow.
-
85% 失败
Import order does not fix a broken _imaging C extension.