成功解决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


image.png


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、博主自己的解决办法

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

image.png


大功告成!


相关文章
|
7月前
|
安全 开发者 C++
Windows10安装modelscope后import这个模块报错:OSError: [WinError 1] 函数不正确。: 'D:\Anaconda\envs\MDS\lib\site-packages\modelscope\utils\ast_utils.py'
Windows10安装modelscope后import这个模块报错:OSError: [WinError 1] 函数不正确。: 'D:\Anaconda\envs\MDS\lib\site-packages\modelscope\utils\ast_utils.py'
237 1
|
5月前
|
IDE 开发工具 Python
【Python】已完美解决:SyntaxError: Non-UTF-8 code starting with ‘æ‘ in file E:/Python/3.py on line 4, but no
【Python】已完美解决:SyntaxError: Non-UTF-8 code starting with ‘æ‘ in file E:/Python/3.py on line 4, but no
152 0
|
3月前
|
索引 Python
File "site-packages\pandas\core\indexing.py", line File "site-packages\pandas\core\indexing.py", l
File "site-packages\pandas\core\indexing.py", line File "site-packages\pandas\core\indexing.py", l
|
3月前
|
缓存 Python
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-npf9报错
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-npf9报错
|
5月前
|
数据安全/隐私保护 Python
【Python】已解决:WARNING: Ignoring invalid distribution -addlepaddle (d:\soft\python36\lib\site-packages)
【Python】已解决:WARNING: Ignoring invalid distribution -addlepaddle (d:\soft\python36\lib\site-packages)
1043 1
|
5月前
|
安全 网络协议 网络安全
【Python】已解决:pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool (host=’ files. pyth
【Python】已解决:pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool (host=’ files. pyth
444 0
|
5月前
|
Python
安装 supervisor报错执行python setup.py install时No local packages or working download links found for meld3
安装 supervisor报错执行python setup.py install时No local packages or working download links found for meld3
37 0
|
Python
Python常见问题 - pip报错 ValueError: Unable to find resource t64.exe in package pip._vendor.distlib
Python常见问题 - pip报错 ValueError: Unable to find resource t64.exe in package pip._vendor.distlib
434 0
Python常见问题 - pip报错 ValueError: Unable to find resource t64.exe in package pip._vendor.distlib
|
7月前
|
机器学习/深度学习 并行计算 安全
ImportError: DLL load failed while importing libpaddle: 找不到指定的模块。问题处理
【5月更文挑战第12天】ImportError: DLL load failed while importing libpaddle: 找不到指定的模块。问题处理
2308 0
|
6月前
|
机器学习/深度学习 并行计算 安全
ImportError: DLL load failed while importing libpaddle: 找不到指定的模块问题
【6月更文挑战第7天】ImportError: DLL load failed while importing libpaddle: 找不到指定的模块问题
444 0