Python 2.7 PIL打开JPEG格式错误的图片,Mac Lion

时间:2012-04-11 03:26:31

标签: python osx-lion python-imaging-library

我曾尝试http://mail.python.org/pipermail/image-sig/2010-June/006313.html,但我仍然收到错误

dreampuf@HX:~/hub/lweibo$ python2.7 lweibo.py 
Traceback (most recent call last):
  File "lweibo.py", line 235, in <module>
    lweibo_render(107906)
  File "lweibo.py", line 228, in lweibo_render
    p = LPic(a_body, a_title, a_ukey_nickname, a_ukey_img, a_create)
  File "lweibo.py", line 114, in __init__
    a_ukey_img.save("s.png", "PNG", qualty=100)
  File "/Users/dreampuf/opt/macports/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Pillow-1.7.7-py2.7-macosx-10.7-x86_64.egg/PIL/Image.py", line 1406, in save
    self.load()
  File "/Users/dreampuf/opt/macports/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Pillow-1.7.7-py2.7-macosx-10.7-x86_64.egg/PIL/ImageFile.py", line 215, in load
    raise_ioerror(e)
  File "/Users/dreampuf/opt/macports/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Pillow-1.7.7-py2.7-macosx-10.7-x86_64.egg/PIL/ImageFile.py", line 52, in raise_ioerror
    raise IOError(message + " when reading image file")
IOError: broken data stream when reading image file

然后我尝试使用Macports来安装jpeg6b,但它提醒我,jpeg6b太旧版本并重命名为jpeg

dreampuf@HX:~/lweibo$ sudo port install jpeg6b
Password:
--->  Configuring jpeg6b
Error: jpeg6b has been renamed to jpeg. Please install jpeg instead.
Error: Target org.macports.configure returned: obsolete port
Log for jpeg6b is at: /Users/dreampuf/opt/macports/var/macports/logs/_Users_dreampuf_opt_macports_var_macports_sources_rsync.macports.org_release_tarballs_ports_graphics_jpeg6b/jpeg6b/main.log
Error: Status 1 encountered during processing.
To report a bug, see <http://guide.macports.org/#project.tickets>

但是jpeg的版本是8d。

 dreampuf@HX:~/hub/lweibo$ port installed jpeg
 The following ports are currently installed:
  jpeg @8d_0 (active)

我知道这个错误的原因是什么。但我无法在我的系统中安装jpeg6b,或无法重新安装PIL以使用jpeg6b

1 个答案:

答案 0 :(得分:0)

我不明白你的第一个写出PNG的例子和然后讨论jpeg问题之间的相关性。

如果你依赖于你的libjpeg的macports,为什么不用它来安装PIL?
构建PIL时,您可以告诉它在哪里查找JPEG库: export JPEG_ROOT=/usr/local/include

我建议删除PIL,删除libjpeg ...然后重新安装最新的jpeg,然后重建PIL。

尝试使用pip安装PIL:pip install -U PIL