我已经在 Mac OS X 上安装了Sage。看起来它有 PIL。以下代码给了我一个 IOError ..
import Image
a = Image.open("pic.jpg")
a.thumbnail((int(100), int(100)))
这是我得到的错误。
IOError Traceback (most recent call last)
<ipython console> in <module>()
/sage/local/lib/python2.6/site-packages/PIL/Image.pyc in thumbnail(self, size, resample)
1520 self.draft(None, size)
1521
-> 1522 self.load()
1523
1524 try:
/sage/local/lib/python2.6/site-packages/PIL/ImageFile.pyc in load(self)
178
179 for d, e, o, a in self.tile:
--> 180 d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
181 seek(o)
182 try:
/sage/local/lib/python2.6/site-packages/PIL/Image.pyc in _getdecoder(mode, decoder_name, args, extra)
373 return apply(decoder, (mode,) + args + extra)
374 except AttributeError:
--> 375 raise IOError("decoder %s not available" % decoder_name)
376
377 def _getencoder(mode, encoder_name, args, extra=()):
IOError: decoder jpeg not available
在我看来,它似乎找不到 libjpeg。我检查了我机器上的 MacPorts,看起来 jpeg 包已经安装。我还在 /opt/local/lib 中找到了 libjpeg。我尝试使用 os 库在 sage 脚本中和在 Sage 中操作 LD_LIBRARY_PATH,但无法摆脱此错误。我在网上搜索了如何让PIL找到libjpeg,但我发现涉及修改setup.py重建PIL。sage 似乎不包含 PIL 的 setup.py。
有没有其他人遇到过这个问题并解决了?也许有人熟悉 PIL?