IOError:OS X 10.10上没有编码器jpeg

时间:2015-05-27 02:45:48

标签: python-2.7 jpeg python-imaging-library osx-yosemite encoder

我试图安装Python Image Library,并且有消息告诉我安装成功

    --------------------------------------------------------------------
    PIL 1.1.7 SETUP SUMMARY
    --------------------------------------------------------------------
    version       1.1.7
    platform      darwin 2.6.9 (unknown, Sep  9 2014, 15:05:12)
                  [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)]
    --------------------------------------------------------------------
    --- TKINTER support available
    --- JPEG support available
    --- ZLIB (PNG/ZIP) support available
    --- FREETYPE2 support available
    *** LITTLECMS support not available
    --------------------------------------------------------------------

但是当我运行代码时,得到了一些错误消息,可能告诉我我没有安装JPEG库

/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Users/tian/PycharmProjects/helloworld/image_test.py
Traceback (most recent call last):
  File "/Users/tian/PycharmProjects/helloworld/image_test.py", line 35, in <module>
    image.save('code.jpg', 'jpeg')
  File "/Library/Python/2.7/site-packages/PIL/Image.py", line 1439, in save
    save_handler(self, fp, filename)
  File "/Library/Python/2.7/site-packages/PIL/JpegImagePlugin.py", line 471, in _save
    ImageFile._save(im, fp, [("jpeg", (0,0)+im.size, 0, rawmode)])
  File "/Library/Python/2.7/site-packages/PIL/ImageFile.py", line 495, in _save
    e = Image._getencoder(im.mode, e, a, im.encoderconfig)
  File "/Library/Python/2.7/site-packages/PIL/Image.py", line 401, in _getencoder
    raise IOError("encoder %s not available" % encoder_name)
IOError: encoder jpeg not available

当我在Google中搜索此错误的原因时,大多数解决方案是重新安装PIL,但是当我安装PIL时,我得到了“JPEG支持可用”消息,因此它不应该由JPEG库引起。然后,我该如何解决这个问题?

我的操作系统是OS X Yosemite 10.10

1 个答案:

答案 0 :(得分:1)

我使用Pillow而不是PIL解决了这个问题,并使用“form PIL import Image”而不是“import Image”。