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

Also available as: JSON · Markdown · 中文
80%Fix Rate
88%Confidence
0Evidence
2024-03-30First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
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

  1. 94% success
    pip uninstall -y PIL Pillow
    pip install --no-cache-dir Pillow
  2. 90% success
    fig.savefig('out.pdf')  # or 'out.svg'

Dead Ends

Common approaches that don't work:

  1. 95% fail

    The 'PIL' package on PyPI is a stub that raises an error; the correct package is Pillow.

  2. 85% fail

    Import order does not fix a broken _imaging C extension.