PIL在mac下报没有安装_imaging的解决办法

报错信息如下:

In [1]: from PIL import Image as PILImage, ImageDraw, ImageFont
—————————————————————————
ImportError                               Traceback (most recent call last)

/Users/jinguoli/Projects/pbi/ in ()

/Users/jinguoli/Projects/pbi/PIL/ImageFont.py in ()
113 # truetype factory function to create font objects.
114
–> 115 class FreeTypeFont:
116     “FreeType font wrapper (requires _imagingft service)”
117

/Users/jinguoli/Projects/pbi/PIL/ImageFont.py in FreeTypeFont()
133         return self.getmask2(text, mode)[0]
134
–> 135     def getmask2(self, text, mode=”", fill=Image.core.fill):
136         size, offset = self.font.getsize(text)
137         im = fill(”L”, size, 0)

/Users/jinguoli/Projects/pbi/PIL/Image.py in __getattr__(self, id)
34     # module placeholder
35     def __getattr__(self, id):
—> 36         raise ImportError(”The _imaging C module is not installed”)
37
38 try:

ImportError: The _imaging C module is not installed

In [2]: import _imaging
—————————————————————————
ImportError                               Traceback (most recent call last)

/Users/jinguoli/Projects/pbi/tracer1/tracer_server/ in ()

ImportError: dlopen(/Library/Python/2.5/site-packages/PIL/_imaging.so, 2): Library not loaded: /usr/local/lib/libjpeg.62.dylib
Referenced from: /Library/Python/2.5/site-packages/PIL/_imaging.so
Reason: image not found

错误信息很明显,是找不能加载/usr/local/lib/libjpeg.62.dylib,造成,到/usr/local/lib检查:

jinguoli@MacBook:/usr/local/lib$ls -al
total 23592
drwxr-xr-x  11 root      wheel      374 Sep 23 12:38 .
drwxr-xr-x  11 root      wheel      374 Aug 29 14:37 ..
drwxr-xr-x  84 root      wheel     2856 Sep 23 12:20 codecs
-rwxr-xr-x   1 root      staff   152408 Apr  6  2008 libfaac.0.dylib
-rwxr-xr-x   1 jinguoli  staff  1054516 Jan 30  2008 libfreetype.6.dylib
-rwxr-xr-x   1 root      wheel   139472 Aug 21 14:12 libjpeg.62.0.0.dylib
-rw-r–r–   1 root      wheel   160984 Aug 21 14:12 libjpeg.a
lrwxr-xr-x   1 root      wheel       20 Aug 21 14:12 libjpeg.dylib -> libjpeg.62.0.0.dylib
-rwxr-xr-x   1 root      wheel      808 Aug 21 14:12 libjpeg.la
-rwxr-xr-x   1 jinguoli  staff   810076 Dec 17  2007 libmp3lame.0.dylib
-rwxr-xr-x   1 root      staff  9736856 Apr  5  2008 libmp4v2.0.dylib

果然没有libjpeg.62.dylib文件,但有libjpeg.dylib.62.0.0.dylib文件,那就好办了,如下:

jinguoli@MacBook:/usr/local/lib$sudo ln -s libjpeg.62.0.0.dylib libjpeg.62.dylib

试一下看看结果:

In [3]: from PIL import Image as PILImage, ImageDraw, ImageFontIn [4]: import _imaging

In [5]:

没错了,正常运行。

Leave a Comment