- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在使用 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/
我有一个 python 脚本,它创建一个 tar 文件,将文件移动到 tar 文件中,然后删除它们。 我可以毫无问题地手动运行脚本。但是当它从 cron 运行时,它失败了: IOError: [Err
我正在尝试从我的Python脚本打开文件recentlyUpdated.yaml。但当我尝试使用时:。我收到一个错误,内容是:。为什么?我怎样才能解决这个问题?
我正在尝试从我的Python脚本打开文件recentlyUpdated.yaml。但当我尝试使用时:。我收到一个错误,内容是:。为什么?我怎样才能解决这个问题?
我正在尝试从我的Python脚本打开文件recentlyUpdated.yaml。但当我尝试使用时:。我收到一个错误,内容是:。为什么?我怎样才能解决这个问题?
尝试将数据加载为 Excel 作为响应时,出现 IO 请求数据读取错误。 def convert_to_excel(request): field = forms.CharField()
我正在尝试读取文件夹树中的一系列 DICOM 文件,并且我使用下面的代码来运行树,边读取每个文件。问题是我收到确实存在的文件的 IOErrors,我已经检查了文件权限和其他 SO 线程,例如 Pyth
我有一个类可以读取特定格式的文件。这些文件的大小往往大于 8Gb,因此通常会进行压缩。在读取文件时,我想捕获文件未被压缩的错误,但 except IOError: 和 except: 都不会这样做,出
这个问题在这里已经有了答案: open() gives FileNotFoundError / IOError: '[Errno 2] No such file or directory' (8 个
给定这段代码: try: #do something except IOError as message: logging.error(message)
for subdir, dirs, files in os.walk(crawlFolder): for file in files: print os.getcwd()
我正在尝试导入模块并创建其类的对象,如下所示: >>> import scriptsim >>> scriptsim.Simulator() 但出现以下错误: Traceback (most rece
我正在使用以下第三方库在 Django 中编写网络应用程序: Django==1.6.1 argparse==1.2.1 cffi==0.8.1 pycparser==2.10 pylast==0.5
我正在使用 python-crontab module确保每天下午 2 点运行我的脚本。 但是我在执行脚本时遇到了一些 IOErrors Traceback: File "backup.py", li
我正在编写一个程序来更改我的桌面背景。它通过读取文本文件来完成此操作。如果文本文件显示其中一个 BG 文件名,它会将那个保存为我的背景,并将另一个的名称写入文件并关闭它。 我似乎无法让它工作。 这是我
我从未见过 IOError被抛出。文档中关于 IOError 的唯一内容是: Thrown when a serious I/O error has occurred. 没有任何子类或其他明显的东西。
我正在尝试下载链接并将其放置在downloads文件夹中,但是出现权限错误。我是计算机上的管理员用户,我也以管理员模式运行它。仍然我得到同样的错误。 这是我使用的代码: urllib.urlretri
我正在构建一个 Haskell 应用程序,并试图弄清楚如何构建错误处理机制。在实际的应用程序中,我正在使用 Mongo 进行大量工作。但是,为此,我将通过对文件进行基本 IO 操作来进行简化。 因此,
当我尝试重试失败的任务时,我会间歇性地(大约 20% 的时间)从 Celery 收到 IOError 异常。 这是我的任务: @task def update_data(pk_id): tr
我编写了一个 python 脚本,想要将日志写入/var/log/myapp.log 中的文件。然而,在某些平台上这并不存在,或者我们可能没有这样做的权限。既然如此,我想尝试在其他地方写。 def g
我已经使用 getopts 编写了一个脚本来接受四个用户输入项(两个输入文件和两个输出文件)。但由于某种原因,我不断收到此错误: python2.7 compare_files.py -b /tmp/
我是一名优秀的程序员,十分优秀!