Fix Win 10 OSError: dlopen() failed to load a library: cairo / cairo-2 / cairo-gobject-2 / cairo.so.2 Error – Python Tutorial

By | August 9, 2022

When you are using python cairosvg library to convert svg to png, you may find OSError: dlopen() failed to load a library: cairo / cairo-2 / cairo-gobject-2 / cairo.so.2 error. In this tutorial, we will introduce how to fix this error.

osError - dlopen fail to laod cairo library

Activate python 3 environment

If you have install conda, you should activate python 3 environment. Because cairosvg library can be run python 3.5+.

activate py3

Install cairosvg library

pip install cairosvg

Install cairosvg dependencies

This is the most important way, you should install cairosvg dependencies, then this error can be fixed.

(py3) C:\Users\fly165>conda install -c conda-forge cairo

install cairosvg dependencies

Moreover, if this error still exists, you have to install python pycairo library.

pip install pycairo

Then, you will find this error is fixed.

Leave a Reply