Python:PIL - [Errno 32] 保存 .png 时管道损坏
我在这里尝试做的是使用 PIL 将 Tkinter Canvas 的内容保存为 .png 图像。
这是我的保存功能(“图表”是画布)。
def SaveAs():
filename = tkFileDialog.asksaveasfilename(initialfile="Untitled Graph", parent=master)
graph.postscript(file=filename+".eps")
img = Image.open(filename+".eps")
img.save(filename+".png", "png")
但它出现了这个错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1410, in __call__
return self.func(*args)
File "C:\Users\Adam\Desktop\Graphing Calculator\Graphing Calculator.py", line 352, in SaveAs
img.save(filename+".png", "png")
File "C:\Python27\lib\site-packages\PIL\Image.py", line 1406, in save
self.load()
File "C:\Python27\lib\site-packages\PIL\EpsImagePlugin.py", line 283, in load
self.im = Ghostscript(self.tile, self.size, self.fp)
File "C:\Python27\lib\site-packages\PIL\EpsImagePlugin.py", line 72, in Ghostscript
gs.write(s)
IOError: [Errno 32] Broken pipe
我在 Windows 7、Python 2.7.1 上运行它。
我该如何进行这项工作?
What I'm trying to do here is save the contents of a Tkinter Canvas as a .png image using PIL.
This is my save function ('graph' is the canvas).
def SaveAs():
filename = tkFileDialog.asksaveasfilename(initialfile="Untitled Graph", parent=master)
graph.postscript(file=filename+".eps")
img = Image.open(filename+".eps")
img.save(filename+".png", "png")
But it's getting this error:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1410, in __call__
return self.func(*args)
File "C:\Users\Adam\Desktop\Graphing Calculator\Graphing Calculator.py", line 352, in SaveAs
img.save(filename+".png", "png")
File "C:\Python27\lib\site-packages\PIL\Image.py", line 1406, in save
self.load()
File "C:\Python27\lib\site-packages\PIL\EpsImagePlugin.py", line 283, in load
self.im = Ghostscript(self.tile, self.size, self.fp)
File "C:\Python27\lib\site-packages\PIL\EpsImagePlugin.py", line 72, in Ghostscript
gs.write(s)
IOError: [Errno 32] Broken pipe
I'm running this on Windows 7, Python 2.7.1.
How do I make this work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
哦,我刚刚得到同样的错误。我现在已经解决了这个问题,
只需在安装 PIL 和 Ghostscript 后执行以下操作
1) 打开 C:\Python27\Lib\site-packages\PIL\EpsImagePlugin.py
2) 更改第 50 行附近的代码,使其如下所示:
Build Ghostscript command
确保 gswin32c.exe 在 PATH 中,
祝你好运
oh I just get the same error. I have solve it now
just do the following after installing PIL and Ghostscript
1) Open C:\Python27\Lib\site-packages\PIL\EpsImagePlugin.py
2) Change code near line 50 so that it looks like this:
Build ghostscript command
Make sure that gswin32c.exe is in the PATH
good luck
看起来 Ghostscript 可执行文件是出错然后关闭连接。其他人在 同样的问题 http://code.google.com/p/elaphe/issues/detail?id=7" rel="nofollow noreferrer">不同操作系统。
因此,首先我建议您确认 PIL 已正确安装 - 请参阅 FAQ 页面 获取提示。接下来,确保 Ghostscript 已安装并正常运行。最后,确保 Python 可以找到 Ghostscript,例如通过运行在其他地方工作的 PIL 脚本。
哦,还有 - 这里有一些关于抓住破损管道的技巧error 以便您的程序更具弹性、识别问题并警告最终用户。希望有帮助!
It looks like the Ghostscript executable is erroring out and then closing the connection. Others have had this same problem on different OSes.
So, first I would recommend that you confirm that PIL is installed correctly--see the FAQ page for hints. Next, ensure that Ghostscript is installed and working. Lastly, ensure that Python can find Ghostscript, for example by running a PIL script that works elsewhere.
Oh, also--here are some tips on catching the broken pipe error so your program can be more resilient, recognize the problem, and warn the end-user. Hope that helps!
我意识到虽然 Python 2.7 有这个 EPEImagePulgin.py,但 Anaconda 也有它。不幸的是 Anaconda 的文件是旧版本。不幸的是,当您从 Spyder 环境运行时,它会从 anaconda 文件夹中获取 epsimageplugin.py 文件。
所以我遇到了类似的破损管道错误。
当我进入 python 2.7 目录并打开 python 控制台然后运行我的代码时,它运行得很好。
因为最新的 epsimageplugin.py 文件考虑了 Windows 环境和适当的 Ghostscript exe 文件。希望这有帮助。
I have realized that while Python 2.7 has this EPEImagePulgin.py, Anaconda also has it. And unfortunately Anaconda's file is an older version. And unfortunately again, when you run your from Spyder environment it was picking up the epsimageplugin.py file from anaconda folder.
So I was getting similar broken pipe error.
When I went into python 2.7 directory and opened python console and then ran my code, it ran just fine.
Because the lates epsimageplugin.py file takes into consideration the windows environment and appropriate ghostscript exe files. Hope this helps.