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

其他格式: JSON · Markdown 中文 · English
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.

generic

解决方案

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

无效尝试

常见但无效的做法:

  1. 95% 失败

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

  2. 85% 失败

    Import order does not fix a broken _imaging C extension.