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


大功告成!


相关文章
|
8月前
|
安全 开发者 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'
251 1
|
6月前
|
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
174 0
|
4月前
|
索引 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
|
6月前
|
数据安全/隐私保护 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)
1319 1
|
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
442 0
Python常见问题 - pip报错 ValueError: Unable to find resource t64.exe in package pip._vendor.distlib
|
6月前
|
程序员 开发者 Python
【Python】已解决:Traceback (most recent call last): File “C:/python/kfc.py”, line 8, in KfcError: KFC Cra
【Python】已解决:Traceback (most recent call last): File “C:/python/kfc.py”, line 8, in KfcError: KFC Cra
323 0
|
6月前
|
安全 网络协议 网络安全
【Python】已解决:pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool (host=’ files. pyth
【Python】已解决:pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool (host=’ files. pyth
582 0
|
6月前
|
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
55 0
|
Ubuntu 计算机视觉 Python
已解决 ImportError:/opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so:undefined symbol:PyCobject Type。
已解决 ImportError:/opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so:undefined symbol:PyCobject Type。
331 0
已解决 ImportError:/opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so:undefined symbol:PyCobject Type。
|
算法框架/工具 Caffe
File "/usr/local/lib/python3.5/site-packages/dateutil/rrule.py", line 55 raise ValueError
File "/usr/local/lib/python3.5/site-packages/dateutil/rrule.py", line 55 raise ValueError
114 0

热门文章

最新文章