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