Django 1.6: _imagingft C模块未安装

0 投票
2 回答
3618 浏览
提问于 2025-04-18 10:02

我正在我的Django应用中尝试使用Django-simple-captcha这个库,具体的使用方法可以在这个链接找到:http://django-simple-captcha.readthedocs.org/en/latest/usage.html。但是,验证码的图片在我的模板中没有显示出来。当我在浏览器中查看源代码时,出现了以下错误。我已经仔细按照文档的说明操作,并且同步了所有数据库。

Traceback:
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
  114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Library/Python/2.7/site-packages/captcha/views.py" in captcha_image
  46.         font = ImageFont.truetype(settings.CAPTCHA_FONT_PATH, settings.CAPTCHA_FONT_SIZE * scale)
File "/Library/Python/2.7/site-packages/PIL/ImageFont.py" in truetype
  228.         return FreeTypeFont(font, size, index, encoding)
File "/Library/Python/2.7/site-packages/PIL/ImageFont.py" in __init__
  131.             self.font = core.getfont(font, size, index, encoding)
File "/Library/Python/2.7/site-packages/PIL/ImageFont.py" in __getattr__
  42.         raise ImportError("The _imagingft C module is not installed")

Exception Type: ImportError at /captcha/image/f02c7bf84cd31c4caf8d6b2f8931a01689902c83/
Exception Value: The _imagingft C module is not installed

我知道这个问题之前被问过很多次,我也看过好几个StackOverflow的回答,但我还是对接下来该怎么做感到很困惑。

我在我的OSX Mavericks上安装了Pillow这个库。

2 个回答

0

在Ubuntu 14.04上对我来说是有效的:

pip uninstall pil

或者(这取决于你使用的是什么)

 pip uninstall pillow

然后

sudo apt-get update

apt-get install libfreetype6-dev libxft-dev  libjpeg62  libjpeg-devel

在输出结果中,确保安装已经完成

最后

pip install pil

或者

pip install pillow
1

我通过在运行 pip install Pillow 之前,先安装了 freetype 和 freetype2 的开发包,解决了上面的错误。

这个方法在 SuSE Linux 系统上有效。

撰写回答