OSError: cannot open resource ImageFont.py 解决方法

发布时间 2023-04-16 09:01:41作者: myrj

Traceback (most recent call last):
File "C:/python37/pla.py", line 7, in <module>
newfont=ImageFont.truetype('./songti.ttc',60) # Songti.ttc 代表字体,60 代表字号
File "C:\python37\lib\site-packages\PIL\ImageFont.py", line 853, in truetype
return freetype(font)
File "C:\python37\lib\site-packages\PIL\ImageFont.py", line 850, in freetype
return FreeTypeFont(font, size, index, encoding, layout_engine)
File "C:\python37\lib\site-packages\PIL\ImageFont.py", line 211, in __init__
self.font = core.getfont(font, size, index, encoding, layout_engine=layout_engine)
OSError: cannot open resource

方案:字体文件路径  字体文件名不能改名(保持原名)