$ 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?
3 Answers
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

- 1,045
- 7
- 15
-
1thank you for your help i typed what you suggested but still the same error – Emna Aug 28 '20 at 09:54
I had same issue.
In my error, it lists the file location of where the code needs to be placed.
C:\users\me\radioconda\lib\site-packages\gnuradio\grc\main.py
When i used a notepad to edit the file I found the code from the post above, but after a set of three import commands.
from gi.repository import Gtk
import argparse
import logging
import sys
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('PangoCairo', '1.0')
I changed the order to this and no longer receive the error. I hope this helps.
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('PangoCairo', '1.0')
from gi.repository import Gtk
import argparse
import logging
import sys
-
There are a ')' missing in the line `gi.require_version('PangoCairo', '1.0'` – Gonzalo Odiard Nov 28 '22 at 23:07
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.
-
This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31705878) – Cornelius Roemer May 12 '22 at 00:58