报错信息
阅读报错信息,
return freetype(font) ,
return FreeTypeFont(font, size, index, encoding, layout_engine)
OSError: cannot open resource
一般报错此原因一般是资源文件使用有问题。
失败原因:
1、首先看自己绑定的路径是否正确,有些人直接绑定到C:\Windows\Fonts该路径下的字库文件,这样是可以的,但是\在Python中要用/
2、绑定到了C:\Windows\Fonts下字库确发现无法使用,原因:字库可能名称过长,这时候我们可把其重命名,然后重新安装至该路径,或者直接放自己绑定的路径即可
3、绑定的路径正确却还是报错,将字库托入C:\Windows\Fonts中,看是否安装,未安装可能无法使用
File "./ClothStore/captcha/captcha.py", line 123, in <listcomp>
for size in font_sizes or (65, 70, 75)])
File "/home/ClothStore/venv/lib/python3.7/site-packages/PIL/ImageFont.py", line 655, in truetype
return freetype(font)
File "/home/ClothStore/venv/lib/python3.7/site-packages/PIL/ImageFont.py", line 652, in freetype
return FreeTypeFont(font, size, index, encoding, layout_engine)
File "/home/ClothStore/venv/lib/python3.7/site-packages/PIL/ImageFont.py", line 194, in __init__
font, size, index, encoding, layout_engine=layout_engine
OSError: cannot open resource