我想使用Elaphe来生成条形码。
当我运行示例代码时,我得到了gs失败的错误。
我在一个64位的windows机器上工作。我安装了Python2.7.1 for win32,因为某些包需要win32。所以,我安装了Ghostscript 9.0.4 win32。我将正确的路径添加到path变量。
我使用easy_install安装了elaphe、python映像库和python ghostscript0.41egg(不确定这是否有必要)。
我可以将elaphe和PIL导入到python中并执行命令,而不会出现错误。每当我尝试将条形码保存为图像时,我都会遇到错误。
当我运行这个简单的用法示例时:
>>> from elaphe import barcode
>>> barcode('qrcode',
... 'Hello Barcode Writer In Pure PostScript.',
... options=dict(version=9, eclevel='M'),
... margin=10, data_mode='8bits')) # Generates PIL.EpsImageFile instance
<PIL.EpsImagePlugin.EpsImageFile instance at ...>
>>> _.show() # Show the image我得到了IOError: [Errno 32] Broken pipe
当我运行此命令来检查ghostscript和PIL安装时:
# coding: utf-8
from StringIO import StringIO
from PIL.EpsImagePlugin import EpsImageFile
src = """%!PS-Adobe 2.0
%%BoundingBox: 0 0 144 144
36 36 72 72 rectfill
/Courier findfont 12 scalefont setfont
36 120 moveto (text) show
showpage
"""
im = EpsImageFile(StringIO(src))
im.save('foo.png')我得到了IOError: gs failed (status 1)
我试着为win64安装Ghostscript,但是我得到了同样的错误。
对从哪里开始故障排除有什么建议吗?我可以运行ghostscript可执行文件,弹出一个命令窗口,并将正确的路径添加到环境路径变量中。
谢谢。
发布于 2011-11-18 20:32:21
您需要捕获Ghostscript输出以查看错误消息是什么。这通常是写到stderr中的,我不知道它在Python库中的位置,但你真的需要看看它,才能弄清楚为什么Ghostscript会退出。
您还需要查看它,以确定Ghostscript是否正在执行。听起来好像不是,但我对"python ghostscript 0.41蛋“一无所知。
发布于 2012-01-02 20:26:36
我也遇到了同样的问题,并通过以下步骤修复了它:
site packages安装PIL和Ghostscript
中下载文件(EpsImagePlugin.py)的python安装目录
https://stackoverflow.com/questions/8178388
复制相似问题