Question:
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
This class is a common font problem. In Windows environment, fonts are generally located in the C:\windows\fonts folder. In this folder, users can check whether the font specified in the python program exists.
fnt = ImageFont.truetype('Pillow/Tests/fonts/FreeMono.ttf', 50)
Solution 1:
Change the font that exists on the computer
ImageFont.truetype("Pillow/Tests/fonts/arial.ttf", 50)
Solution 2:
Found no freemono in the computer Ttf font, so you need to download
https://fontmeme.com/ziti/freemono-font/
After downloading, unzip it into the fonts folder
finally. Restart the computer to execute.