在windows上安装Ghostscript以便与Elaphe Python barcode gen一起使用时进行故障排除

2024-06-30 07:59:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用Elaphe生成条形码。在

当我运行示例代码时,我得到了gs失败的错误。在

我在一台64位的windows机器上工作。我安装了python2.7.1forwin32,因为某些包需要win32。所以,我安装了Ghostscript 9.0.4 Win32。我向path变量添加了正确的路径。在

我使用easy_install安装了elaphe、python图像库和pythonghostscript0.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安装时:

^{pr2}$

我得到IOError: gs failed (status 1)

我试着为win64安装Ghostscript,但是我得到了同样的错误。在

关于从何处开始故障排除有何建议?我可以运行ghostscript可执行文件,然后弹出一个命令窗口,并将正确的路径添加到env path变量中。在

谢谢。在


Tags: pathinstance图像路径gs示例pil错误
2条回答

您需要捕获Ghostscript输出以查看错误消息是什么。这通常是写到stderr中的,我不知道它在Python库中的位置,但是您确实需要看到它来找出Ghostscript退出的原因。在

您还需要查看它,以确定是否正在执行Ghostscript。听起来好像不是,但我对“python ghostscript 0.41egg”一无所知。在

我遇到了同样的问题,并通过以下步骤解决了它:

  1. 安装PIL和Ghostscript
  2. 浏览到http://code.google.com/p/elaphe/issues/detail?id=7
  3. 一直到底部,下载附件(EpsImagePlugin.py)在
  4. 备份当前副本EpsImagePlugin.py在C:\Python26\Lib\site packages\PIL下。当然,将“C:\Python26”替换为python安装目录
  5. 放置下载的文件(EpsImagePlugin.py)在C:\Python26\Lib\site packages\PIL中

相关问题 更多 >