2012-01-31 13 views
7

Tôi đang sử dụng ReportLab để in biểu đồ được tạo bởi matplotlib.IOError: "bộ giải mã zip không khả dụng" bằng cách sử dụng PNG matplotlib trong ReportLab trên Linux, hoạt động trên Windows

Tôi có thể thực hiện việc này trên máy phát triển Windows của mình mà không gặp sự cố nào. Tuy nhiên, khi tôi triển khai một máy chủ Ubuntu, kết xuất không thành công với lỗi được mô tả. Tôi cho rằng tôi thiếu một mô-đun Python, nhưng tôi không biết cái nào. Tôi tin rằng các phiên bản của Python, matplotlib, ReportLab và PIL giống nhau trên cả máy phát triển và máy chủ của tôi.

Mã để chuyển đổi hình matplotlib (gọi là biểu đồ) để PNG và gửi lại:

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

return img_stream 

Mã để sử dụng hình ảnh:

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

Khi chạy trên Windows, hoạt động này. Khi chạy trên Linux, lỗi này tạo ra lỗi này:

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=[[email protected]] 
    handle_pageBegin args=() 
+1

Có vẻ như bạn đang thiếu mô-đun zlib. Hãy xem tại đây http://www.foxhop.net/ubuntu-python-easy_install-pil-does-not-install-zlib-support – RanRag

+0

Bạn có tự biên dịch PIL không? Hoặc là PIL được quản lý bởi 'apt'? – sarnold

+0

@sarnold: Tôi tin PIL đã được ReportLab cài đặt. Trong mọi trường hợp, tôi đã không xây dựng nó, tôi đã nhận nó hoặc là một phần của cái gì khác hoặc với easy_install trên Windows và apt-get trên Ubuntu. –

Trả lời

12

Rõ ràng PIL setup.py không biết cách tìm libz.so. PIL dự kiến ​​libz.so sẽ được đặt trong /usr/lib không phải /usr/lib/i386-linux-gnu/libz.so.

Để khắc phục vấn đề

1) Tìm vị trí của hệ thống của bạn libz.so sử dụng find . -name libz.so.

2) Tạo liên kết mềm từ libz.so tới/usr/lib bằng cách sử dụng sudo ln -s /usr/lib/i386-linux-gnu/libz.so /usr/lib.

3) Và vì @Larry đề nghị bạn phải cài đặt lại PIL sau khi liên kết sym với zlib.

Để giải quyết sự cố này cho hệ thống 64 bit, hãy xem tại đây http://www.foxhop.net/ubuntu-python-easy_install-pil-does-not-install-zlib-support

+0

Tôi có cùng một vấn đề nhưng tôi thiếu libz.so. Chạy linux mint và arch cung cấp cho tôi i686 – ralphtheninja

+1

Sửa lỗi này cùng một lỗi với thư viện Pillow. – Druska

Các vấn đề liên quan