欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

成功解决OSError: cannot open resource File F:Python36\lib\site-packages\PIL\ImageFont.py, self.font

发布时间:2025/3/21 python 55 豆豆
生活随笔 收集整理的这篇文章主要介绍了 成功解决OSError: cannot open resource File F:Python36\lib\site-packages\PIL\ImageFont.py, self.font 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

成功解决OSError: cannot open resource File "F:Python36\lib\site-packages\PIL\ImageFont.py", self.font

 

 

目录

解决问题

解决思路

解决方法


 

 

 

解决问题

  File "F:Python36\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

 

解决思路

 self.font = core.getfont(font, size, index, encoding, layout_engine=layout_engine)
OSError:无法打开资源,
两个原因
T1、加载的字体文件路径不对!,很有可能是加载的文件名字过长,文件名过长也不行的!
T2、加载的字体文件有问题!

 

解决方法

1、先参考StackOverflow网友的解答:https://stackoverflow.com/questions/47694421/pil-issue-oserror-cannot-open-resource

I have also met this issue on Windows 10 Pro with PIL 5.3.0.
On my machine, the error is caused by non-ASCII font file names. If I change the the font name to only contain ASCII characters, I can open the font without any error.

 

2、博主自己的解决办法
博主是因为加载字体的文件路径不对造成的!把字体放在同代码文件夹下边即可!博主更改加载路径的方法也成功!

大功告成!

 

 

 

 

 

 

 

总结

以上是生活随笔为你收集整理的成功解决OSError: cannot open resource File F:Python36\lib\site-packages\PIL\ImageFont.py, self.font的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。