操作系统错误:无法在路径中找到Ghostscript

15

我尝试使用Pyzo打开一个EPS图像,我已经安装了PIL和Ghostscript(因为我在其他网站上看到这是必要的),我的代码如下:

from PIL import Image
im = Image.open('''myimage.eps''')
im.show()

但当我运行代码时,Pyzo会返回:

OSError:在路径上无法找到Ghostscript

我试着在几个网站上查看,但对于一个新手编码学生来说似乎相当复杂。


这个链接解决了我的问题:https://www.tutorialexample.com/fix-oserror-unable-to-locate-ghostscript-on-paths-for-python-beginners-python-tutorial/ - Amin Saqi
2个回答

10
若有人遇到此问题:看起来 Ghostscript 尚未正确添加至路径中。对于运行 Win7 的用户,这是一种解决方法:
前往: 控制面板 -> 系统 -> 高级系统设置 -> 环境变量...
找到变量“PATH”-> 编辑... -> 添加路径到 ghostscript 二进制文件夹,例如

C:\Program Files\gs\gs9.22\bin\;

添加到该变量的末尾。它应与上一个条目由分号分隔。
更改生效前,我必须重新启动计算机。

3
我曾使用 pip install ghostscript ,以为这样能得到相同的结果。但实际上你需要手动下载 GhostScript 并设置环境变量。 - Pavisa

9
你需要安装 Ghostscript
  1. 下载: https://www.ghostscript.com/download/gsdnld.html

  2. 告诉变量(EpsImagePlugin.gs_windows_binary) EXE(gswin64c, gswin32c, gs) 的路径。(如果您不想更改系统路径。

from PIL import EpsImagePlugin
EpsImagePlugin.gs_windows_binary =  r'X:\...\gs\gs9.52\bin\gswin64c'
im = Image.open('myimage.eps')
im.save('myimage.png')

您可以在 PIL.EpsImagePlugin.py 上看到以下内容。
# EpsImagePlugin.py

__version__ = "0.5"

...

gs_windows_binary = None  # 

def Ghostscript(tile, size, fp, scale=1):
    """Render an image using Ghostscript"""

    ...

    if gs_windows_binary is not None:
        if not gs_windows_binary:   # 
            raise WindowsError("Unable to locate Ghostscript on paths")
        command[0] = gs_windows_binary

这就是为什么我告诉你要设置gs_windows_binary的原因。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接