ImageFont IO error: cannot open resource

Looks like you can install Coval from here to save you from having to change fonts in future code as well https://fontlibrary.org/en/font/bretan


It's because Coval.otf cannot be read, probably because it doesn't exist on your system, this is specified in the ImageFont doc. I tried searching for the specific font and found no way of aquiring it. Look at @NewYork167's link if you must use the Coval font.

Either way, to save yourself the trouble of installing fonts, you could just change the call to a font that exists on your system, use the one specified in the example of the docs:

font = ImageFont.truetype("arial.ttf", 15)

If you are using colab then you will have to provide path properly just writing arial.ttf is not sufficient. To get the path if that font-type is available on colab : !fc-list or !fc-list | grep "" and then you can add the whole path.enter image description here


For me after running the following:

conda install -c conda-forge graphviz
conda install -c conda-forge python-graphviz

and then linking the font on mac by:

 img = Image.open("tree1.png")
 draw = ImageDraw.Draw(img)
 font = ImageFont.truetype('/Library/Fonts/Arial.ttf', 15)

It worked perfectly.