枕头未加载图像-无法识别图像文件 [英] Pillow not loading image -cannot identify image file
本文介绍了枕头未加载图像-无法识别图像文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码段出了什么问题?
What's wrong with the following snippet?
它与图像格式无关,我同时尝试了jpg和png.
It's not related to the image format, I tried both with jpg and png.
import Image
from cStringIO import StringIO
with open('/path/to/file/image.png') as f:
data = f.read()
img = Image.open(StringIO(data))
img.load()
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
File "/usr/lib64/python2.7/site-packages/PIL/Image.py", line 2030, in open
raise IOError("cannot identify image file")
IOError: cannot identify image file
在互联网上随机下载的图片和以下最基本的片段会发生这种情况:
This does happen with a randomly downloaded picture from the internet and the following most basic snippet:
import Image
im = Image.open('WicZW.jpg')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/site-packages/PIL/Image.py", line 2030, in open
raise IOError("cannot identify image file")
IOError: cannot identify image file
推荐答案
问题出在机器上PIL和Pillow库的相互存在:
The problem was in the mutual presence of the PIL and Pillow library on the machine:
# pip freeze | grep -E '(Pillow|PIL)'
PIL==1.1.7
Pillow==2.1.0
这篇关于枕头未加载图像-无法识别图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文