2

我正在使用枕头在 python (2.7.4 - 64 位 windows 7) 中打开图像链接下载枕头在这里:http : //www.lfd.uci.edu/~gohlke/pythonlibs/ (Pillow-2.1.0. win-amd64-py2.7.‌exe)

但是安装后,打开图像时总是出错。例子:

import Image
import cStringIO

temp_file = open('C:\\Users\\Desktop\\images.png', 'rb+')
content = cStringIO.StringIO(temp_file.read())
image = Image.open(content)

我收到错误:

Traceback (most recent call last):
  File "C:\Users\Desktop\test.py", line 7, in <module>
    image = Image.open(content)
  File "C:\Python27\lib\site-packages\PIL\Image.py", line 2008, in open
    raise IOError("cannot identify image file")
IOError: cannot identify image file

我该如何解决?

4

2 回答 2

2

我认为你应该这样做:

from PIL import Image
image=Image.open('C:\\Users\\Desktop\\images.png')

我不明白为什么你会在这个例子中使用 cStringIO。还要注意导入行的区别。

于 2013-07-13T16:12:00.650 回答
0

I had the same issue. In my case I had not uninstalled PIL before installing PILLOW. Once I uninstalled PIL, then uninstalled PILLOW, then reinstalled PILLOW, everything worked.

于 2013-08-30T20:23:47.763 回答