Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Usually at work I lock my screen when I leave, log off once a week, and rarely reboot. All my packages are up-to-date.

Yesterday I rebooted, and this morning I can't launch my Python3/Gtk3 apps :

JeanCoiron@myhostname:/opt/myapps/dev$ ./mywindow.py 
Traceback (most recent call last):
  File "./mywindow.py", line 4, in <module>
    from gi.repository import Gtk
  File "/usr/lib/python3/dist-packages/gi/importer.py", line 76, in load_module
  File "/usr/lib/python3/dist-packages/gi/module.py", line 224, in _load
    overrides_modules = __import__('gi.overrides', fromlist=[self._namespace])
  File "/usr/lib/python3/dist-packages/gi/overrides/Gtk.py", line 1533, in <module>
    raise RuntimeError("Gtk couldn't be initialized")
RuntimeError: Gtk couldn't be initialized

Code of this example app :

# Filename: mywindow.py

from gi.repository import Gtk
from gi.repository import Gdk

class MyWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title="My window")

        self.mainGrid = Gtk.Grid()

        self.lbl = Gtk.Label("Hello World")

mainWin = MyWindow()
mainWin.connect("delete-event", Gtk.main_quit)


If I launch it from Geany it works, not from a standard terminal. Same for all my python3/gtk3 apps. From a Geany terminal echo $PATH is exactly the same as from a standard terminal. Curently DISPLAY=':0', I tried with no DISPLAY var and with DISPLAY='localhost:0'

Any idea where I should search ?


This is a Gtk issue only : I can launch Gtk apps like gedit from Unity launcher but not from a terminal.

JeanCoiron@myhostname:/opt/myapps/dev$ gedit /usr/lib/python3/dist-packages/gi/overrides/Gtk.py
Cannot open display: 
Run 'gedit --help' to see a full list of available command line options.
JeanCoiron@myhostname:/opt/myapps/dev$ echo $DISPLAY
share|improve this question
Try to run this script with python 2 explicitly to see if problems persists. Also checking what line that RuntimeError throws gives some more insight. Apparently it's Gtk.init_check() which fails, so Googling that might give some more useful results. –  Timo Mar 28 '13 at 10:33
The error is exactly the same using python2 (python2 ./mywindow.py) –  Jean Coiron Mar 28 '13 at 11:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.