OSError:无法在路径上找到 Ghostscript

A.R*_*uet 8 operating-system eps python-imaging-library pyzo

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

from PIL import Image
im = Image.open('''myimage.eps''')
im.show()
Run Code Online (Sandbox Code Playgroud)

但是当我运行代码时,Pyzo 返回给我:`

OSError: Unable to locate Ghostscript on paths
Run Code Online (Sandbox Code Playgroud)

我试图在几个网站上研究它,但对于一个新手编码学生来说似乎很复杂。

我正在研究 Python 3

谢谢各位大侠帮忙

(哦,我是法国人,所以也许我的英语不是很完美!)

Car*_*ard 9

你需要Ghostscript

  1. 下载: https: //www.ghostscript.com/download/gsdnld.html

  2. 告诉变量( ) EXE( , , )EpsImagePlugin.gs_windows_binary的路径是什么。(如果您不想更改系统路径。gswin64cgswin32cgs

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

可以在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
Run Code Online (Sandbox Code Playgroud)

这就是为什么我告诉你要设定意志gs_windows_binary


Jan*_*nis 7

如果其他人遇到此问题:似乎 Ghostscript 没有正确添加到路径中。对于那些运行 Win7 的人,这里有一个修复:

转到:控制面板 -> 系统 -> 高级系统设置 -> 环境变量...

找到变量“PATH”-> 编辑...-> 将路径添加到您的 ghostscript 二进制文件夹中,例如

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

到变量的末尾。它应该用分号与前一个条目分开。

我必须重新启动才能使更改生效。

  • 一直以来,我都使用 `pip install ghostscript` 认为它会产生相同的结果。显然您必须手动下载 gs 并设置环境变量。 (3认同)