【问题标题】:OSError: Unable to locate Ghostscript on pathsOSError:无法在路径上找到 Ghostscript
【发布时间】:2017-11-19 02:53:45
【问题描述】:

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

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

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

OSError: 无法在路径上找到 Ghostscript

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

【问题讨论】:

标签: python operating-system python-imaging-library eps pyzo


【解决方案1】:

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

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

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

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

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

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

【讨论】:

  • 我一直使用pip install ghostscript 认为它会产生相同的结果。显然你必须手动下载 gs 并设置环境变量。
【解决方案2】:

你需要ghostscript

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

  2. 告诉变量(EpsImagePlugin.gs_windows_binary)EXE(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')

您可以在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 会起作用。

【讨论】:

    猜你喜欢
    • 2020-11-15
    • 2022-08-19
    • 2015-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-06
    • 1970-01-01
    • 2015-05-12
    相关资源
    最近更新 更多