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.
Activate python 3 environment
If you have install conda, you should activate python 3 environment. Because cairosvg library can be run python 3.5+.
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
Moreover, if this error still exists, you have to install python pycairo library.
pip install pycairo
Then, you will find this error is fixed.