'PyGIWarning: Gtk and Rsvg were imported without specifying a version first. Use gi.require_version

$ python -c 'from gi.repository import Gtk' -c:1: PyGIWarning: Gtk was imported without specifying a version first. Use gi.require_version('Gtk', '3.0') before import to ensure that the right version gets loaded. what should i do?



Solution 1:[1]

You got a warning because you are importing gtk wihtouht specifing the version. This is because gtk has several version so you should declare which want to use.

In order to do so you can open a python terminal (type python on your commandline) and execute the following code:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

Solution 2:[2]

I had the same issue as described in the question. I tried to change the order of the above listed commands in the source file, but some extension of VS Code was resetting the order to bottom up the oder suggested in the above answer. When I force-saved the code with the sequence as suggested, it solved the query. This might work in most cases. Thank you.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 pokoli
Solution 2 Ajudiya Kenil