skip to Main Content

$ 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


  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
    
    Login or Signup to reply.
  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.

    Login or Signup to reply.
  3. I had same issue.

    In my error, it lists the file location of where the code needs to be placed.

    C:usersmeradiocondalibsite-packagesgnuradiogrcmain.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      
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search