使用 pip install pillow
安装了 PIL 后,在 python from PIL import Image
正常,运行如下代码异常,经过调试是在调用 save
方法是报错的:
from PIL import Image
img = Image.open(fileName+'.eps')
img.save(fileName+'.png')
有谁知道怎么办不?(sprio.py
是我自己的文件)
具体报错:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python36\lib\tkinter\__init__.py", line 1699, in __call__
return self.func(*args)
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python36\lib\turtle.py", line 686, in eventfun
fun()
File "D:/python_workspace/MachineStudy/jike_project/ch02/spiro.py", line 183, in saveDrawing
img.save('11.png')
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python36\lib\site-packages\PIL\Image.py", line 1897, in save
self.load()
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python36\lib\site-packages\PIL\EpsImagePlugin.py", line 337, in load
self.im = Ghostscript(self.tile, self.size, self.fp, scale)
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python36\lib\site-packages\PIL\EpsImagePlugin.py", line 137, in Ghostscript
raise WindowsError('Unable to locate Ghostscript on paths')
OSError: Unable to locate Ghostscript on paths
你確認一下你的 ghost script 有在系統路徑中(
PATH
), 沒有的話去修改環境變量將之加入PATH
中。可以稍微參考一下這篇 的方法來修改 windows 的環境變量。
另外對於引發的
OSError
,這裡有 source code 可以參考。我回答過的問題: Python-QA