pygobject/pycairo

Cannot import cairo in python 3.10

agn-7 opened this issue · 3 comments

agn-7 commented
pip install -U pycairo

Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pycairo in /usr/lib/python3/dist-packages (1.16.2)
Collecting pycairo
  Using cached pycairo-1.21.0-cp310-cp310-linux_x86_64.whl
Installing collected packages: pycairo
Successfully installed pycairo-1.21.0
>>> import cairo

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/cairo/__init__.py", line 1, in <module>
    from ._cairo import *  # noqa: F401,F403
ModuleNotFoundError: No module named 'cairo._cairo'
lazka commented

I'm a bit confused. The first part says you installed it to user site-packages, the next message says you load it from the system directory, which in theory shouldn't be possible.

agn-7 commented

Most likely that was why I've tried to install it using various methods including pip, sudo pip, as well as apt. So I uninstalled pycariro and reinstalled it normally as follows:

sudo pip uninstall pycairo
pip uninstall pycairo
sudo apt remove python-cairo:amd64
sudo apt remove libcairo
sudo rm -rf /usr/lib/python3/dist-packages/cairo 
pip install -U --ignore-installed pycairo

Defaulting to user installation because normal site-packages is not writeable
Collecting pycairo
  Using cached pycairo-1.21.0-cp310-cp310-linux_x86_64.whl
Installing collected packages: pycairo
Successfully installed pycairo-1.21.0
pip show pycairo

Name: pycairo
Version: 1.21.0
Summary: Python interface for cairo
Home-page: https://pycairo.readthedocs.io
Author: 
Author-email: 
License: LGPL-2.1-only OR MPL-1.1
Location: /home/benyamin/.local/lib/python3.10/site-packages
Requires: 
Required-by: 

But, I don't why I cannot import cairo again however with a different error:

import cairo
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-381c76bbfa70> in <module>
----> 1 import cairo

ModuleNotFoundError: No module named 'cairo'
lazka commented

Not idea, sorry. This doesn't look like a pycairo problem to me.

As a general rule, never run pip as root (except in docker maybe), it will mess up your system Python install