【问题标题】:IOError: "decoder zip not available" using matplotlib PNG in ReportLab on Linux, works on WindowsIOError:“解码器 zip 不可用”在 Linux 上的 ReportLab 中使用 matplotlib PNG,适用于 Windows
【发布时间】:2012-01-31 01:55:00
【问题描述】:

我正在使用 ReportLab 打印 matplotlib 生成的图表。

我可以在我的 Windows 开发机器上毫无问题地执行此操作。但是,当我部署到 Ubuntu 服务器时,渲染失败并出现描述的错误。我假设我缺少一个 Python 模块,但我不知道是哪一个。我相信 Python、matplotlib、ReportLab 和 PIL 的版本在我的开发机器和服务器上都是相同的。

将matplotlib图形(称为图表)转换为PNG并返回的代码:

img_stream = StringIO.StringIO()
chart.savefig(img_stream, format = 'png')
img_stream.seek(0)

return img_stream

图片使用代码:

    res_img = charts.CreateProjectionChart(doc.fund) #calls above code
    if res_img:
        img = ImageReader(res_img)
        canvas.drawImage(img, FromLeft(first_col), FromTop(3.5, 2), width - (.1 * inch), 1.75 * inch, preserveAspectRatio=True, anchor='c')

在 Windows 上运行时,此方法有效。在 Linux 上运行时会产生以下错误:

  File "/home/web-server/reports.py", line 913, in FirstPageSetup
    canvas.drawImage(img, FromLeft(first_col), FromTop(3.5, 2), width - (.1 * inch), 1.75 * inch, preserveAspectRatio=True, anchor='c')
  File "/usr/local/lib/python2.7/dist-packages/reportlab-2.5-py2.7-linux-x86_64.egg/reportlab/pdfgen/canvas.py", line 840, in drawImage
    rawdata = image.getRGBData()
  File "/usr/local/lib/python2.7/dist-packages/reportlab-2.5-py2.7-linux-x86_64.egg/reportlab/lib/utils.py", line 658, in getRGBData
    annotateException('\nidentity=%s'%self.identity())
  File "/usr/local/lib/python2.7/dist-packages/reportlab-2.5-py2.7-linux-x86_64.egg/reportlab/lib/utils.py", line 648, in getRGBData
    if Image.VERSION.startswith('1.1.7'): im.load()
  File "/usr/local/lib/python2.7/dist-packages/PIL-1.1.7-py2.7-linux-x86_64.egg/ImageFile.py", line 189, in load
    d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
  File "/usr/local/lib/python2.7/dist-packages/PIL-1.1.7-py2.7-linux-x86_64.egg/Image.py", line 385, in _getdecoder
    raise IOError("decoder %s not available" % decoder_name)
IOError: decoder zip not available
identity=[ImageReader@0x30336d0]
   handle_pageBegin args=()

【问题讨论】:

  • 您似乎缺少 zlib 模块。看看这里foxhop.net/…
  • 你自己编译过PIL吗?还是 PIL 由 apt 管理?
  • @sarnold:我相信 PIL 是由 ReportLab 安装的。无论如何,我没有构建它,我将它作为其他东西的一部分或在 Windows 上使用 easy_install 和在 Ubuntu 上使用 apt-get 获得。
  • @RanRag:我能够使用这些说明来解决问题(必须在符号链接 zlib 的 so 后重新安装 PIL。请作为答案发布,以便您可以要求您的积分(以及有相同问题的下一个人可以找到答案)。
  • @LarryLustig :如果您觉得有任何遗漏或错误,请编辑它。

标签: python png python-imaging-library reportlab


【解决方案1】:

显然 PIL setup.py 不知道如何找到 libz.so。 PIL 期望 libz.so 位于 /usr/lib 而不是 /usr/lib/i386-linux-gnu/libz.so

解决问题

1) 使用 find . -name libz.so 查找系统 libz.so 的位置。

2) 使用sudo ln -s /usr/lib/i386-linux-gnu/libz.so /usr/lib 创建从 libz.so 到 /usr/lib 的软链接。

3) 正如@Larry 建议的那样,您必须在为 zlib 符号链接 so 后重新安装 PIL。

要解决 64 位系统的这个问题,请看这里http://www.foxhop.net/ubuntu-python-easy_install-pil-does-not-install-zlib-support

【讨论】:

  • 我有同样的问题,但我缺少 libz.so。运行 linux mint 和 arch 给我 i686
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-01
相关资源
最近更新 更多