gpt4 book ai didi

python - IOError : "decoder zip not available" using matplotlib PNG in ReportLab on Linux, 适用于 Windows

转载 作者:太空狗 更新时间:2023-10-29 21:29:50 25 4
gpt4 key购买 nike

我正在使用 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=()

最佳答案

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

解决问题

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

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

3) 正如@Larry 建议的那样,您必须在对 zlib 进行符号链接(symbolic link)后重新安装 PIL。

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

关于python - IOError : "decoder zip not available" using matplotlib PNG in ReportLab on Linux, 适用于 Windows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9073455/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com