Skip to main content
 首页 » 编程设计

python之升级 python 图像库 (PIL) 时,它告诉我 "JPEG support not available"

2025年05月04日22youxin

使用 ubuntu 13.10,python 2.7.5:

>>> import _imaging, Image 
>>> from PIL import Image, ImageDraw, ImageFilter, ImageFont 
>>> im = Image.new('RGB', (300,300), 'white') 
>>> draw = ImageDraw.Draw(im) 
>>> font = ImageFont.truetype('arial.ttf', 14) 
Traceback (most recent call last): 
  File "<stdin>", line 1, in <module> 
  File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFont.py", line 218, in truetype 
    return FreeTypeFont(filename, size, index, encoding) 
  File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFont.py", line 134, in __init__ 
    self.font = core.getfont(file, size, index, encoding) 
  File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFont.py", line 34, in __getattr__ 
    raise ImportError("The _imagingft C module is not installed") 
**ImportError: The _imagingft C module is not installed** 
>>> 

那么为什么会这样呢?我该如何解决?我按照在 this thread 底部找到的以下说明进行操作:

pip uninstall PIL 
apt-get install libjpeg-dev 
apt-get install libfreetype6-dev 
apt-get install zlib1g-dev 
apt-get install libpng12-dev 
pip install PIL --upgrade 

但是在升级PIL的时候,看看我看到了什么:

-------------------------------------------------------------------- 
PIL 1.1.7 SETUP SUMMARY 
-------------------------------------------------------------------- 
version       1.1.7 
platform      linux2 2.7.5+ (default, Sep 19 2013, 13:48:49) 
              [GCC 4.8.1] 
-------------------------------------------------------------------- 
*** TKINTER support not available 
*** JPEG support not available 
*** ZLIB (PNG/ZIP) support not available 
*** FREETYPE2 support not available 
*** LITTLECMS support not available 
-------------------------------------------------------------------- 

对所有这些项目不提供支持是否正常?我该如何解决?

请您参考如下方法:

PIL 基本上已经死了, fork Pillow真的是你应该使用的。您需要通过

导入它
from PIL import Image, ... 

它保留了 PIL 的所有功能,并添加了更多功能,包括 Python 3 兼容性。此外,与 PIL 不同,它正在积极开发中,因此您发现的任何错误实际上都有机会得到修复 - 与功能请求一样。

您可以通过运行安装它(在卸载 PIL 之后)

pip install Pillow 

我相信有一个适用于 Ubuntu 的软件包,但我的虚拟机目前让我很头疼,我无法检查...