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


大功告成!


相关文章
|
4月前
|
安全 开发者 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'
91 1
|
6月前
|
XML Shell Linux
python内置模块(random、os、sys、shelve、configparser、xml)
python内置模块(random、os、sys、shelve、configparser、xml)
46 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
384 0
Python常见问题 - pip报错 ValueError: Unable to find resource t64.exe in package pip._vendor.distlib
|
10月前
|
Python
【python3.6】pyinstaller报错AssertionError: Failed to determine matplotlib‘s data directory!【解决方案】
【python3.6】pyinstaller报错AssertionError: Failed to determine matplotlib‘s data directory!【解决方案】
173 0
|
算法框架/工具 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
85 0
成功解决PermissionError: [WinError 5] 拒绝访问 \lib\\site-packages\\h5py\\_errors.cp38-win_amd64.pyd‘
成功解决PermissionError: [WinError 5] 拒绝访问 \lib\\site-packages\\h5py\\_errors.cp38-win_amd64.pyd‘
(Anaconda)ImportError: DLL load failed while importing win32file: 找不到指定的模块。
(Anaconda)ImportError: DLL load failed while importing win32file: 找不到指定的模块。
(Anaconda)ImportError: DLL load failed while importing win32file: 找不到指定的模块。
|
Python
解决 Traceback (most recent call last):File “D:\FAE\python\lib\runpy.py“, line 193
解决 Traceback (most recent call last):File “D:\FAE\python\lib\runpy.py“, line 193
1457 0
|
Python
Python 常见问题 - 使用 poetry build 打包构建失败,报 ModuleOrPackageNotFound No file/folder found for package filesystemfastapi
Python 常见问题 - 使用 poetry build 打包构建失败,报 ModuleOrPackageNotFound No file/folder found for package filesystemfastapi
274 0
Python 常见问题 - 使用 poetry build 打包构建失败,报 ModuleOrPackageNotFound No file/folder found for package filesystemfastapi
|
Python
WARNING: Ignoring invalid distribution -ip (e:\python\lib\site-packages)
WARNING: Ignoring invalid distribution -ip (e:\python\lib\site-packages)
630 0
WARNING: Ignoring invalid distribution -ip (e:\python\lib\site-packages)