IOError: “decoder zip not available” using matplotlib PNG in ReportLab on Linux, works on Windows

狂风中的少年 提交于 2019-12-04 20:57:14

问题


I'm using ReportLab to print a chart produced by matplotlib.

I'm able to do this on my Windows development machine without trouble. When I deploy to a Ubuntu server, however, the rendering fails with the error described. I assume I'm missing a Python module, but I don't know which one. I believe the versions of Python, matplotlib, ReportLab and PIL are the same on both my development machine and the server.

Code to convert the matplotlib figure (called chart) to PNG and return it:

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

return img_stream

Code to use the image:

    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')

When run on Windows, this works. When run on Linux it produces this error:

  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=()

回答1:


Apparently PIL setup.py doesn't know how to find libz.so. PIL expects libz.so to be located in /usr/lib not /usr/lib/i386-linux-gnu/libz.so.

To fix the problem

1) Find the location of your systems libz.so using find . -name libz.so.

2) Create a soft link from libz.so to /usr/lib using sudo ln -s /usr/lib/i386-linux-gnu/libz.so /usr/lib.

3) And as @Larry suggested you had to reinstall PIL after sym-linking the so for zlib.

To solve this problem for 64-bit system take a look here http://www.foxhop.net/ubuntu-python-easy_install-pil-does-not-install-zlib-support



来源:https://stackoverflow.com/questions/9073455/ioerror-decoder-zip-not-available-using-matplotlib-png-in-reportlab-on-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!