首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >Python <`没有这样的文件或目录:'gs'>错误*UPDATE*

Python <`没有这样的文件或目录:'gs'>错误*UPDATE*
EN

Stack Overflow用户
提问于 2016-01-14 03:29:12
回答 1查看 978关注 0票数 0

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

代码语言:javascript
代码运行次数:0
运行
复制
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')

但是,每当我运行这个保存函数时,我都会得到如下错误:

代码语言:javascript
代码运行次数:0
运行
复制
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'**,是什么?为什么会发生这种情况,以及如何解决导致此错误的问题?**

FYI: --以防万一,我的操作系统是Macintosh,我的版本是3.5.1

编辑:显然,正如我所想的那样,'gs'的意思是GhostScript,而这个错误的发生是因为我必须安装它(感谢让我意识到这一点的答案)。我已经安装了.dmg从这里,,但我仍然继续得到错误的。也许这和我现在的操作系统(MacOS10.11.2)有关吧?或者我的保存功能有什么问题?老实说我不知道。无论如何,尽管我(希望)再次安装了?,但是为什么这个错误仍然会继续发生呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-14 03:31:50

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34781217

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档