How do you use GTK with Python and Poetry

How do you set up GTK with Python and Poetry?
When I try to :

poetry add PyGObject

I get info that pycairo can’t be installed:

        Package cairo was not found in the pkg-config search path.
        Perhaps you should add the directory containing `cairo.pc'
        to the PKG_CONFIG_PATH environment variable
        Package 'cairo', required by 'virtual:world', not found
        Command '['pkg-config', '--print-errors', '--exists', 'cairo >= 1.15.10']' returned non-zero exit status 1.
        [end of output]
    
    note: This error originates from a subprocess, and is likely not a problem with pip.
    ERROR: Failed building wheel for pycairo
  Failed to build pycairo
  ERROR: Could not build wheels for pycairo, which is required to install pyproject.toml-based projects

But I guess the problem is around installing those deps, as outside of it I have libcairo 1.16 and pycairo 1.20.

In general I have to admit that getting started with GTK and Python is a bit frustrating for a noob. This is just another roadblock. So far I’ve added pygobject-stubs to get rid of some import error messages, but pyright still complains about some things. And the thing is my searches didn’t brought me many guides to get started.

Since poetry appears to build pycairo from source in its own venv instead of using your system copy of pycairo, you’ll probably need the development files of libcairo installed as well.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.