python3 PIL使用font字体错误:OSError: cannot open resource问题解决

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/m0_37422289/article/details/81362959

错误日志

>>> from PIL import ImageFont
>>> ImageFont.truetype
<function truetype at 0x0000021178B82B70>
>>> ImageFont.truetype("NotoSansCJK-Regular.ttc", 30)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Users\52489\Anaconda3\lib\site-packages\PIL\ImageFont.py", line 261, in truetype
    return FreeTypeFont(font, size, index, encoding, layout_engine)
  File "D:\Users\52489\Anaconda3\lib\site-packages\PIL\ImageFont.py", line 144, in __init__
    self.font = core.getfont(font, size, index, encoding, layout_engine=layout_engine)
OSError: cannot open resource

解决方法:

缺少对应字体文件: NotoSansCJK-Regular.ttc
在网上找到对应的font文件
环境为Ubuntu 16
ttc文件放到 /usr/share/fonts/truetype 文件夹当中.
重新启动python环境,即可正常导入.

猜你喜欢

转载自blog.csdn.net/m0_37422289/article/details/81362959