问题描述
我正在运行OS X 10.6.7,Python 2.6,并编写了一个小的wxPython应用程序,该应用程序使用PIL来操纵图像并向其中添加一些文本.
I'm running OS X 10.6.7, Python 2.6, and writing a small wxPython application that uses PIL to manipulate an image and add some text to it.
尝试通过libjpeg和PIL运行PIL的大量配置问题后,我按照此站点.
After quite a bit of configuration woes with attempting to get PIL running with libjpeg and PIL, I followed the instructions at this site.
运行python setup.py build_ext -i
(从Imaging-1.1.7文件夹内部)后,我得到:
Upon running python setup.py build_ext -i
(from inside the Imaging-1.1.7 folder) I get:
--------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version 1.1.7
platform darwin 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)]
--------------------------------------------------------------------
--- TKINTER support available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- FREETYPE2 support available
--- LITTLECMS support available
--------------------------------------------------------------------
另外,在Imaging-1.1.7安装文件夹中运行python selftest.py
,我得到:
Additionally, running python selftest.py
in the Imaging-1.1.7 install folder, I get:
--------------------------------------------------------------------
PIL 1.1.7 TEST SUMMARY
--------------------------------------------------------------------
Python modules loaded from ./PIL
Binary modules loaded from ./PIL
--------------------------------------------------------------------
--- PIL CORE support ok
--- TKINTER support ok
--- JPEG support ok
--- ZLIB (PNG/ZIP) support ok
--- FREETYPE2 support ok
--- LITTLECMS support ok
--------------------------------------------------------------------
Running selftest:
--- 57 tests passed.
但是,当用自己的代码渲染我的第一个PIL图像时,我仍然得到:
However, when rendering my first PIL image in my own code, I still get:
File "/Library/Python/2.6/site-packages/PIL/Image.py", line 1290, in resize self.load()
File "/Library/Python/2.6/site-packages/PIL/ImageFile.py", line 215, in load raise_ioerror(e)
File "/Library/Python/2.6/site-packages/PIL/ImageFile.py", line 52, in raise_ioerror
raise IOError(message + " when reading image file")
IOError: broken data stream when reading image file
接下来的尝试让我有些茫然.有任何想法吗?导致此崩溃的代码似乎是:
I'm kind of at a loss as to what to try next. Any ideas? The code that is causing this crash seems to be:
try:
self.img = self.img.resize((self.screenwidth, self.screenheight),
Image.ANTIALIAS)
except IOError, e:
print "Error resizing: " + str(e)
self.img = self.img.resize((self.screenwidth, self.screenheight))
raise
推荐答案
您应考虑卸载PIL并按照此网站上的说明进行操作- http://jetfar.com/libjpeg-and-python -imaging-pil-on-snow-leopard/
You should consider uninstalling PIL and following the instructions on this website -http://jetfar.com/libjpeg-and-python-imaging-pil-on-snow-leopard/
尤其是您似乎想要确保libjpeg的版本为 6b ,而不是 8c (请参见下文)
In particular, it appears that you want to make sure that libjpeg is at version 6b, not 8c (see below)
我可以使用Macports在Mac OS X 10.5上重现此内容
I am able to reproduce this with Mac OS X 10.5 using macports
这与另一个问题有关:如何解决IOError:读取图像文件时数据流中断?
This is related to a another question:How to solve IOError:broken data stream when reading image file?
那里的答案表明该错误可能与libjpeg有关
The answer there indicates that the bug might have something to do with libjpeg
据我所知,该错误似乎是由于与libjpeg v8c的向前不兼容引起的.
As far as I can tell, the error appears to be caused by a forward incompatibility with libjpeg v8c.
我无法确定到底是什么原因造成的;我所能说的是,在我使用的各种其他系统上,这些系统均未显示此行为错误(带芬克的OS X 10.5,Redhat 5.2,Ubuntu 11.10和10.10),它们都使用libjpeg 6b.只有macports使用8c,而macports是唯一出现此错误的系统.
I cannot determine what is causing this exactly; all I can say is that on a variety of other systems I use that aren't exhibiting this behavior error (OS X 10.5 with fink, Redhat 5.2, Ubuntu 11.10 and 10.10), they all use libjpeg 6b. Only macports uses 8c, and macports is the only system where I am getting this error.
这篇关于“错误:读取图像文件时数据流中断". (在OS X上为TrueType字体libjpeg和PIL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!