我在我的程序中实现了以下save
函数,它允许用户将他/她在Tkinter画布上与Turtle一起绘制的任何东西保存为JPEG文件。它的工作原理是,它首先捕获屏幕和Tkinter画布,然后基于它创建一个postscript文件。然后将postscript文件转换为PIL ()可读文件类型,然后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'
**,是什么?为什么会发生这种情况,以及如何解决导致此错误的问题?**
FYI: --以防万一,我的操作系统是Macintosh,我的版本是3.5.1
编辑:显然,正如我所想的那样,'gs'
的意思是GhostScript,而这个错误的发生是因为我必须安装它(感谢让我意识到这一点的答案)。我已经安装了.dmg从这里,,但我仍然继续得到错误的。也许这和我现在的操作系统(MacOS10.11.2)有关吧?或者我的保存功能有什么问题?老实说我不知道。无论如何,尽管我(希望)再次安装了?,但是为什么这个错误仍然会继续发生呢?
发布于 2016-01-13 19:31:50
PIL将PostScript文件创建委托给未安装在系统上的GhostScript。安装它。
https://stackoverflow.com/questions/34781217
复制相似问题