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

大功告成!

 

 

 

 

 

 

 

  • 14
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一个处女座的程序猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值