Python教程

python报错: OSError: cannot open resource

本文主要是介绍python报错: OSError: cannot open resource,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

问题:

  File "D:\Windows_DL_Environment\anaconda3\envs\py37\lib\site-packages\PIL\ImageFont.py", line 852, in freetype
    return FreeTypeFont(font, size, index, encoding, layout_engine)
  File "D:\Windows_DL_Environment\anaconda3\envs\py37\lib\site-packages\PIL\ImageFont.py", line 212, in __init__
    font, size, index, encoding, layout_engine=layout_engine
OSError: cannot open resource

此类是常见的字体问题,在Windows环境,字体一般位于C:\WINDOWS\Fonts文件夹下。用户可以到此文件夹中查看Python程序中指定的字体是否存在。

fnt = ImageFont.truetype('Pillow/Tests/fonts/FreeMono.ttf', 50)

发现电脑中并没有FreeMono.ttf字体,因此需要下载
https://fontmeme.com/ziti/freemono-font/

下载后解压带Fonts文件夹中就好了
在这里插入图片描述最后。重启电脑在去执行。

这篇关于python报错: OSError: cannot open resource的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!