python
install_error
ai_generated
true
ImportError: cannot import name '_imaging' from 'PIL' (PIL is required for image saving)
ID: python/matplotlib-agg-pillow-missing
80%Fix Rate
88%Confidence
0Evidence
2024-03-30First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
Pillow is not installed or a broken partial install exists, so matplotlib cannot save PNG/JPEG via the Agg backend.
generic中文
未安装 Pillow 或存在损坏的部分安装,导致 matplotlib 无法通过 Agg 后端保存 PNG/JPEG。
Workarounds
-
94% success
pip uninstall -y PIL Pillow pip install --no-cache-dir Pillow
-
90% success
fig.savefig('out.pdf') # or 'out.svg'
Dead Ends
Common approaches that don't work:
-
95% fail
The 'PIL' package on PyPI is a stub that raises an error; the correct package is Pillow.
-
85% fail
Import order does not fix a broken _imaging C extension.