【问题标题】:Python <`No such file or directory: 'gs'> error *UPDATE*Python <`没有这样的文件或目录:'gs'>错误*更新*
【发布时间】:2016-01-14 03:29:12
【问题描述】:

我在我的程序中实现了以下save 函数,它允许用户将他/她使用 Turtle 在 Tkinter 画布上绘制的任何内容保存为 JPEG 文件。它的工作原理是它首先捕获屏幕和 Tkinter 画布,然后基于它创建一个 postscript 文件。然后它将 postscript 文件转换为 PIL(Python 图像库)可读文件类型,然后 PIL 将转换后的文件保存为 JPEG。我的保存功能如下图:

def savefirst(): 
    # Capture screen and Tkinter canvas
    cnv = getscreen().getcanvas() 
    global hen
    # Save screen and canvas as Postscript file
    ps = cnv.postscript(colormode = 'color')
    # Open a Tkinter file dialog that allows to input his.her own name for the file
    hen = filedialog.asksaveasfilename(defaultextension = '.jpg')
    # Convert Postscript file to PIL readable format
    im = Image.open(io.BytesIO(ps.encode('utf-8')))
    # Finally save converted file as a JPEG
    im.save(hen + '.jpg')

但是,每当我运行此保存功能时,都会收到如下所示的错误:

line 2396, in savefirst
    im.save(hen + '.jpg')
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/PIL/Image.py", line 1646, in save
    self.load()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/PIL/EpsImagePlugin.py", line 337, in load
    self.im = Ghostscript(self.tile, self.size, self.fp, scale)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/PIL/EpsImagePlugin.py", line 143, in Ghostscript
    stdout=subprocess.PIPE)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 950, in __init__
    restore_signals, start_new_session)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 1544, in _execute_child
    raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'gs'

什么是'gs',为什么会发生这种情况,我将如何解决导致此错误的问题?

仅供参考:以防万一,我的操作系统是 Macintosh,我的 Python 版本是 3.5.1

编辑: 显然,正如我所想的那样,'gs' 表示 GhostScript,并且由于我必须安装它而发生该错误(感谢答案让我意识到这一点)。我已经从here 安装了.dmg,但我仍然不断收到错误。也许这与我当前的操作系统(Mac OS 10.11.2)有关?还是我的保存功能有其他问题?老实说,我不知道。 无论如何,即使我(希望)安装了 GhostScript,为什么这个错误仍然出现?再次,非常感谢任何帮助!

【问题讨论】:

    标签: python python-3.x canvas tkinter python-imaging-library


    【解决方案1】:

    PIL 将 PostScript 文件的创建委托给您的系统上未安装的 GhostScript。安装它。

    【讨论】:

    • 好吧,这就是我的想法。只是想确定一下。但是,我搜索了很多,但找不到与我的 Python 版本(3.5.1)兼容的 GhostScript 版本。我什至在终端中完成了pip install GhostScript,但我仍然收到此错误。
    • GhostScript 是一个完全独立的应用程序。它不需要与 Python 兼容。
    • 等等,GhostScript 不是 Python 的模块?
    • 没有。它是一个完整的独立 PostScript 引擎。
    • 好吧,我已经访问了 GhostScript 网站,是的,你是对的。但是,有 4 次下载。 PostScript 转换应该使用哪一个?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-12
    • 2022-10-21
    • 2021-10-31
    • 1970-01-01
    • 2020-03-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多