PIL无法识别Mac OS下的jpeg库

flo*_*sch 5 python macos python-imaging-library

这样的脚本:

from PIL import Image, ImageOps
img = Image.open('1.JPG')
thumb = ImageOps.fit(img, (200,200) , Image.ANTIALIAS, (0.5, 0.5))
Run Code Online (Sandbox Code Playgroud)

导致此IOError:

Traceback (most recent call last):
  (...)
  File "/Library/Python/2.7/site-packages/PIL/Image.py", line 385, in _getdecoder
    raise IOError("decoder %s not available" % decoder_name)
IOError: decoder jpeg not available
Run Code Online (Sandbox Code Playgroud)

如何获得我的PIL的jpeg支持?这个问题似乎众所周知,但现有的线程并没有为我解决.我使用brew和pip作为我的python包,并且已经尝试了以下内容:

  • brew install jpeg 原因 Error: jpeg-8d already installed
  • brew install libjpeg 原因 Error: jpeg-8d already installed
  • sudo pip install Pillow - 安装有效,但不会改变任何东西

如何获得我的PIL安装的jpeg支持?有任何想法吗?

flo*_*sch 8

我不明白为什么,但重新安装PIL修复了这个问题:

sudo pip uninstall pil
sudo pip install pil
Run Code Online (Sandbox Code Playgroud)

  • 好吧,您似乎在安装PIL后安装了jpeg库.jpeg库在编译时链接,这就是你必须重新安装PIL的原因. (4认同)