I have a rather strange scenario. I'm running on a very old installation, so I've compiled most of the tools I use.
First, this is a server. It is exclusively used by SSH-ing into it. But whoever set this server up made some strange choices. Instead of creating separate users, there is one user on login called fphyiscs, with a home directory of /home/fphysics. (Access is controlled strictly via public key/private key authentication. So everybody logs in as "fphysics", but there are no passwords.) Then there are "profile" directories in this one. For instance, mine is /home/fphysics/joelfred. There is a script that is run by fphysics on login that looks through the directories in /home/fphysics and interprets these as "profile". You can then choose which "profile" you want to use. The script then sources a file called "ENVS" in this profile directory.
I thought this was weird. But I know better than to argue with a sysadmin. So I work within this system. I set up my ENVS to source a more conventional .bash_profile, instead of just setting up environment variables as they probably intended. I set my HOME environment variable in ENVS: export HOME=/home/fphysics/joelfred. The software on this system is so outdated that I've compiled tons of my own stuff, using a prefix of $HOME/opt. So my path now includes $HOME/opt/bin. I sym-linked /home/fphysics/.Xauthority to /home/fphyiscs/joelfred/.Xauthority, so x sessions work over SSH. I honestly don't remember all the hacky things I've done to make this work more normally, and so I can have access to more current software. (For instance, GCC is v4.1.2, copyright 2006.)
I've since tried to compile and install Matplotlib, with the GTK3Agg backend. This means, of course, that I had to compile a lot of x libraries, GTK, pygobject, etc., etc. At some point along the line, I had to compile DBUS. Now, I have some interesting/annoying Matplotlib behavior. This, for instance, works as expected:
fphysics@facet-srv01 ~$ ipython
Python 2.7.3 (default, Apr 30 2013, 00:58:45)
Type "copyright", "credits" or "license" for more information.
IPython 0.13.2 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import matplotlib.pyplot as plt
** (ipython:1648): WARNING **: Couldn't connect to accessibility bus: Failed to connect to socket /tmp/dbus-oWyQu0DxxF: Connection refused
In [2]: import numpy as np
In [3]: x=np.linspace(-10,10,100)
In [4]: y=x*x
In [5]: plt.plot(x,y)
Out[5]: [<matplotlib.lines.Line2D at 0xacb2eec>]
In [6]: plt.show()
This works as expected - I get a plot of a parabola. I get a window that blocks my ipython terminal. The window, as far as I can tell, has full functionality. When I close it, I get returned to my ipython terminal. Note the strange dbus error though - I have NO IDEA where it gets the /tmp/dbus-oWyQu0DxxF idea. I've looked and I don't get it.
Okay. So now I want to turn on interactive mode:
fphysics@facet-srv01 ~$ ipython
Python 2.7.3 (default, Apr 30 2013, 00:58:45)
Type "copyright", "credits" or "license" for more information.
IPython 0.13.2 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import matplotlib.pyplot as plt
** (ipython:4181): WARNING **: Couldn't connect to accessibility bus: Failed to connect to socket /tmp/dbus-oWyQu0DxxF: Connection refused
In [2]: import numpy as np
In [3]: plt.ion()
In [4]: x=np.linspace(-10,10,100)
In [5]: y=x*x
In [6]: plt.plot(x,y)
Out[6]: [<matplotlib.lines.Line2D at 0xb0f1fcc>]
I get nothing. Weird. I try a show:
In [7]: plt.show()
Nothing. I try a draw:
In [8]: plt.draw()
I get a window with a title of "Figure 1", but it's gray. I try another draw:
In [9]: plt.draw()
Now I get a window with my parabola. But no buttons work. I can't even close the window. So I try a close:
In [10]: plt.close()
Nothing happens. Okay. I'll exit my ipython terminal:
In [11]: exit
Window goes away, no errors. But what happens if I don't do a show or a draw or just exit? I get weird errors:
fphysics@facet-srv01 ~$ ipython
Python 2.7.3 (default, Apr 30 2013, 00:58:45)
Type "copyright", "credits" or "license" for more information.
IPython 0.13.2 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import matplotlib.pyplot as plt
** (ipython:7262): WARNING **: Couldn't connect to accessibility bus: Failed to connect to socket /tmp/dbus-oWyQu0DxxF: Connection refused
In [2]: import numpy as np
In [3]: plt.ion()
In [4]: x=np.linspace(-10,10,100)
In [5]: y=x*x
In [6]: plt.plot(x,y)
Out[6]: [<matplotlib.lines.Line2D at 0xb636bf6c>]
In [7]: exit
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/home/fphysics/joelfred/opt/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "/home/fphysics/joelfred/opt/lib/python2.7/site-packages/matplotlib/_pylab_helpers.py", line 87, in destroy_all
manager.destroy()
File "/home/fphysics/joelfred/opt/lib/python2.7/site-packages/matplotlib/backends/backend_gtk3.py", line 415, in destroy
self.canvas.destroy()
AttributeError: FigureManagerGTK3Agg instance has no attribute 'canvas'
Error in sys.exitfunc:
Traceback (most recent call last):
File "/home/fphysics/joelfred/opt/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "/home/fphysics/joelfred/opt/lib/python2.7/site-packages/matplotlib/_pylab_helpers.py", line 87, in destroy_all
manager.destroy()
File "/home/fphysics/joelfred/opt/lib/python2.7/site-packages/matplotlib/backends/backend_gtk3.py", line 415, in destroy
self.canvas.destroy()
AttributeError: FigureManagerGTK3Agg instance has no attribute 'canvas'
So I dug into dbus - the only error I can see that may be affecting things. I have two installations apparently:
fphysics@facet-srv01 ~$ $HOME/opt/bin/dbus-daemon --version
D-Bus Message Bus Daemon 1.7.2
Copyright (C) 2002, 2003 Red Hat, Inc., CodeFactory AB, and others
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
fphysics@facet-srv01 ~$ /bin/dbus-daemon --version
D-Bus Message Bus Daemon 1.1.2
Copyright (C) 2002, 2003 Red Hat, Inc., CodeFactory AB, and others
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Maybe they're competing? I don't know. I've symlinked /home/fphysics/.dbus to /home/fphysics/joelfred/.dbus. That doesn't seem to help. I'm at a loss. I have no idea what's going on. How do I diagnose this? How do I get dbus to work in my scenario? How do I test it on a more basic level? What in the world is going on??
BTW, Ipython makes the testing easier, but the behavior is the same if I run from a python prompt.