Search code examples
google-colaboratorycairo

Problem importing Cairo after installation in Google-Colaboratory


I successfully installed Cairo on Colab, but I receive the following error when trying to import it.

!apt-get install python3-Cairo

ModuleNotFoundError: No module named 'cairo._cairo'

I also tried to install the following packages beforehand, but the problem is not solved.

!apt-get install -y libgtk-3-dev python-gi-dev libcairo2 Pycairo


Solution

  • You need to install libcairo2-dev first.

    !apt install libcairo2-dev
    

    Then you can install pycairo and import it.

    !pip install pycairo
    import cairo