[IPython-dev] check_for_gtk fails with no X11 in 0.10.1

John Hunter jdh2358@gmail....
Mon Nov 15 05:57:50 CST 2010


I am unable to use ipython 0.10.1 in a screen session (no X11) because
it fails with the following traceback (included below).   Fernando
initially told me he thought this bug was fixed in 0.10.1 but
apparently not for all cases.  Here is my clean install log

johnh@:~> cd tmp
johnh@:tmp> rm -rf ipython-0.10.1
~/dev/lib/python2.4/site-packages/IPython/ ipython-0.10.1.tar.gz
johnh@:tmp> wget http://ipython.scipy.org/dist/0.10.1/ipython-0.10.1.tar.gz
--05:44:48--  http://ipython.scipy.org/dist/0.10.1/ipython-0.10.1.tar.gz
johnh@:tmp> tar xvfz ipython-0.10.1.tar.gz
...snip
ipython-0.10.1/setupegg.py
ipython-0.10.1/README.txt
ipython-0.10.1/setupbase.py
johnh@:ipython-0.10.1> python setup.py install --prefix=~/dev
...snip
changing mode of /home/titan/johnh/dev/bin/pycolor to 755
changing mode of /home/titan/johnh/dev/bin/irunner to 755
changing mode of /home/titan/johnh/dev/bin/iptest to 755
running install_data
johnh@:~> PYTHONPATH=~/dev/lib/python2.4/site-packages/ ~/dev/bin/ipython
Python 2.4.5 (#4, Apr 12 2008, 09:09:16)
Type "copyright", "credits" or "license" for more information.

IPython 0.10.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object'. ?object also works, ?? prints mo\
re.

In [1]:


So far so good, but now see what happens when gtk is in my path....

johnh@:~> PYTHONPATH=~/dev/lib/python2.4/site-packages/:/opt/app/g++lib6/python-2.4/lib/python2.4/site-packages/3rdParty/gtk-2.6
~/dev/bin/ipython
Xlib: connection to "localhost:14.0" refused by server
Xlib: Invalid MIT-MAGIC-COOKIE-1 key
Traceback (most recent call last):
  File "/home/titan/johnh/dev/bin/ipython", line 28, in ?
    IPython.Shell.start().mainloop()
  File "/home/titan/johnh/dev/lib/python2.4/site-packages/IPython/Shell.py",
line 1258, in start
    shell = _select_shell(sys.argv)
  File "/home/titan/johnh/dev/lib/python2.4/site-packages/IPython/Shell.py",
line 1246, in _select_shell
    th_mode = check_gtk(th_mode)
  File "/home/titan/johnh/dev/lib/python2.4/site-packages/IPython/Shell.py",
line 1154, in check_gtk
    import gtk
  File "/opt/app/g++lib6/python-2.4/lib/python2.4/site-packages/3rdParty/gtk-2.6/gtk/__init__.py",
line 37, in ?
    from _gtk import *
RuntimeError: could not open display


Adding the RuntimeError exception to check_gtk.py works for me --
sorry for simply pasting int he amended function but I do not have a
git branch checked out here.  It is just the inclusion of the two
except RuntimeError lines that is needed.  This may be a gtk version
difference -- some versions may throw a RuntimeError and some may
throw and ImporError --welcome to my world :-)

# amened function in Shell.py:

def check_gtk(mode):
    try:
        import gtk
    except ImportError:
        return mode
    except RuntimeError:
        return mode
    if hasattr(gtk,'set_interactive'):
        gtk.set_interactive(False)
        return 'tkthread'
    else:
        return mode


More information about the IPython-dev mailing list