在EPS格式的情况下,Python PIL Image.save()错误

时间:2014-01-09 10:30:04

标签: python python-imaging-library

我正在尝试将jpeg文件转换为eps文件。我使用以下代码:

fp=open("test.jpg",'rb')
im=Image.open(fp)
outf=open('test2.eps','wb')
im.save(outf, 'EPS')

但是,我收到以下错误:

Traceback (most recent call last):
File "im2eps2.py", line 11, in <module> im.save(outf, 'EPS')
File "C:\Python26\Lib\site-packages\PIL\Image.py", line 1465, in save
save_handler(self, fp, filename)
File "C:\Python26\Lib\site-packages\PIL\EpsImagePlugin.py", line 353, in _save
fp = io.TextIOWrapper(NoCloseStream(fp), encoding='latin-1')
File "C:\Python26\Lib\io.py", line 1429, in __init__
self._seekable = self._telling = self.buffer.seekable()
File "C:\Python26\Lib\site-packages\PIL\EpsImagePlugin.py", line 348, in __getattr__
return getattr(self.fp, name)
AttributeError: 'file' object has no attribute 'seekable'

我将感谢你的建议。 感谢

PS:我从主页面重新安装了PIL,http://www.pythonware.com/products/pil/并且它有效:)早些时候,我使用了http://www.lfd.uci.edu/~gohlke/pythonlibs提供的Windows安装程序。我认为问题出在我之前安装的二进制文件中。目前,我有1.1.7 PIL并且工作正常。

谢谢

1 个答案:

答案 0 :(得分:0)

根据cgohlke,这是Pillow中的一个错误,并已在上个月(2014年4月1日)发布的2.4.0中修复。

来自bug report

  

io.TextIOWrapper期望一个对象具有io.IOBase接口,而不是Python 2 file对象。使用fh = io.open('test.eps', 'wb')通过此阶段,但io.TextIOWrapper.write()期望unicode字符串;示例以TypeError: can't write str to text stream失败。