Python:未安装 _imagingft C 模块

标签 python image python-imaging-library

我尝试了很多在网上发布的解决方案,它们都不起作用。

>>> import _imaging
>>> _imaging.__file__
'C:\\python26\\lib\\site-packages\\PIL\\_imaging.pyd'
>>>

所以系统可以找到_imaging但仍然不能使用truetype字体

from PIL import Image, ImageDraw, ImageFilter, ImageFont


im = Image.new('RGB', (300,300), 'white')
draw = ImageDraw.Draw(im)
font = ImageFont.truetype('arial.ttf', 14)
draw.text((100,100), 'test text', font = font)

引发此错误:

ImportError: The _imagingft C module is not installed

File "D:\Python26\Lib\site-packages\PIL\ImageFont.py", line 34, in __getattr__
  raise ImportError("The _imagingft C module is not installed")

最佳答案

在 Ubuntu 上,您需要在编译 PIL 之前安装 libfreetype-dev。

$ sudo apt-get install libfreetype6-dev
$ sudo -s
\# pip uninstall pil
\# pip install --no-cache-dir pil

PS!在大多数 Ubuntu 版本上,以 sudo 运行 pip install 通常会将软件包安装到/usr/local/lib。您可以考虑将 Pil 安装在用户拥有的路径中的虚拟环境(virtualenv 或 venv)中。

您也可以考虑安装枕头而不是 pil,我认为它与 API 兼容:https://python-pillow.org .请注意,Pillow 还需要 libfreetype-dev,如果在初始安装期间没有 libfreetype-dev,您可能需要执行相同的卸载/安装步骤。

关于Python:未安装 _imagingft C 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4011705/

相关文章:

python - 使用 matplotlib 从 JSON 绘制数据的最简单方法?

ios - Assets 目录在 Xcode 10.3 中返回 nil 图像,在 10.1 中工作正常

python - 尝试使用 PIL 保存图像时出现 IndexError

python - Django 如何判断上传的图片是否有效?

python - 如何使用 python 创建无帧视频而不将其保存到磁盘?

python - 将列表拆分为两个具有相似元素的子列表

python - 为什么 Pylint 不喜欢内置函数?

python - 从整数列表中,获取最接近给定值的数字

javascript - [src] 属性更改后 Angular 5 不重新渲染 img 标签

image - R:哪个热图/图像可以获得没有任何树状图的行排序图?