我正在try 运行一个简单的代码,使用PILRaspbian中的Python3.9中的自定义字体,但我无法通过此错误:

Traceback (most recent call last):
  File "/home/pi/python/src/mintest.py", line 2, in <module>
    font52 = ImageFont.truetype('fonts/Font.ttf', 52)
  File "/home/pi/.local/lib/python3.9/site-packages/PIL/ImageFont.py", line 878, in truetype
    return freetype(font)
  File "/home/pi/.local/lib/python3.9/site-packages/PIL/ImageFont.py", line 875, in freetype
    return FreeTypeFont(font, size, index, encoding, layout_engine)
  File "/home/pi/.local/lib/python3.9/site-packages/PIL/ImageFont.py", line 196, in __init__
    if core.HAVE_RAQM:
  File "/home/pi/.local/lib/python3.9/site-packages/PIL/ImageFont.py", line 70, in __getattr__
    raise ImportError("The _imagingft C module is not installed")
ImportError: The _imagingft C module is not installed

这是在Raspbian中再现错误所需的最小代码:

from PIL import ImageFont   
font52 = ImageFont.truetype('fonts/Font.ttf', 52)

这是我的系统信息

分销商ID:Raspbian

描述:Raspbian GNU/Linux 9.13(扩展)

版本:9.13

代号:拉伸

Python 3.9.6

Output of python3 -m PIL

我已经try 了我在这里看到的所有答案.

推荐答案

通常情况下,我会期待问题的解决方案:

The _imagingft C module is not installed

要安装Freetype库,请执行以下操作:

sudo apt install libfreetype6-dev libfreetype6

然而,解决方案似乎是:

sudo apt-get install libjpeg62-turbo-dev
pip3 install Pillow --no-binary :all:

我不知道为什么-有一个讨论here.

Python相关问答推荐

如何使用matplotlib在Python中使用规范化数据和原始t测试值创建组合热图?

rame中不兼容的d类型

如何创建一个缓冲区周围的一行与manim?

从spaCy的句子中提取日期

利用Selenium和Beautiful Soup实现Web抓取JavaScript表

cv2.matchTemplate函数匹配失败

递归访问嵌套字典中的元素值

使用BeautifulSoup抓取所有链接

为什么if2/if3会提供两种不同的输出?

在极点中读取、扫描和接收有什么不同?

解决Geopandas和Altair中的正图和投影问题

python3中np. divide(x,y)和x/y有什么区别?'

具有不同坐标的tkinter canvs.cocords()和canvs.moveto()

try 在单个WITH_COLUMNS_SEQ操作中链接表达式时,使用Polars数据帧时出现ComputeError

有没有一种方法可以根据不同索引集的数组从2D数组的对称子矩阵高效地构造3D数组?

将标签与山脊线图对齐

ValueError:必须在Pandas 中生成聚合值

如何在Python中画一个只能在对角线内裁剪的圆?

正则表达式反向查找

Pandas 数据框自定义排序功能