2014-01-09 59 views
0

我试图将jpeg文件转换为eps格式。我使用下面的代码:Python PIL Image.save()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,它工作正常。

感谢

+0

我可以运行没有问题你最少的代码示例。也许还有其他事情涉及到你的情况?也许'outf'不是一个真正的文件或类似的? – Alfe

+0

我无法在我的环境中找到问题。我甚至会打印类型(outf)以确保它的确是。所以,outf是类型文件。任何其他线索? – Sanjay

+0

好吧,可能是Windows的问题。我正在Linux上进行测试,所以也许你只是在Windows实现中发现了一个错误。帮不了你,抱歉。但是您确信上面打印的四行代码的最小示例已经显示出问题了?我正在谈论这四条线(和额外的进口报表),没有其他的东西。那些已经在您的计算机上显示问题? – Alfe

回答

0

根据cgohlke这是在枕头中的错误,并已被固定在2.4.0,这是上月公布(2014 4月1日)。

bug report

io.TextIOWrapper expects an object with io.IOBase interface, not a Python 2 file object. Using fh = io.open('test.eps', 'wb') passes this stage but io.TextIOWrapper.write() expects unicode strings; the example fails with TypeError: can't write str to text stream .