27

Setup:

Processor : x86_64 Operating System: GNU/Linux Distro: Fedora Release 13 (Goddard).

Python 2.6.4

 /usr/bin/python

Here is the following issue:

I am trying to generate a few graphs using Matplotlib and Python. As I hear from a majority of the solutions3.. there seem to be compatibility issues between matplotlib and 64bit architectures.

I have installed Matplotlib from here

Here is the error that I get:

Traceback (most recent call last):
  File "plot-thread-characterization.py", line 24, in <module>
    import matplotlib.pyplot as plt
  File "/usr/lib64/python2.6/site-packages/matplotlib/pyplot.py", line 78, in <module>
    new_figure_manager, draw_if_interactive, show = pylab_setup()
  File "/usr/lib64/python2.6/site-packages/matplotlib/backends/__init__.py", line 25, in pylab_setup
    globals(),locals(),[backend_name])
  File "/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_gtkagg.py", line 10, in <module>
    from matplotlib.backends.backend_gtk import gtk, FigureManagerGTK, FigureCanvasGTK,\
  File "/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_gtk.py", line 8, in <module>
    import gtk; gdk = gtk.gdk
  File "/usr/lib64/python2.6/site-packages/gtk-2.0/gtk/__init__.py", line 64, in <module>
    _init()
  File "/usr/lib64/python2.6/site-packages/gtk-2.0/gtk/__init__.py", line 52, in _init
    _gtk.init_check()
RuntimeError: could not open display

Thanks.

2
  • 1
    I don't think this is a linking issue but sounds like it can't create the GTK display. Are you running an X11 server or are you running this over ssh for example? Commented Nov 12, 2012 at 0:12
  • I am running this over a SSH. I am not using the ssh -X option. Commented Nov 12, 2012 at 0:13

1 Answer 1

41

matplotlib is failing to connect to any X server for its GTK display.

There are a couple of options here:

  1. Run a local X server and enable X11 forwarding in your ssh client, to display the output on your local machine. You can verify this is working by checking that the $DISPLAY environment variable is set on the server.

  2. Call matplotlib.use(...) to specify a different display back-end, for example rendering to pdf file, before importing pyplot, e.g.

    import matplotlib as mpl

    mpl.use('Agg')

    import matplotlib.pyplot as plt

See http://matplotlib.org/faq/howto_faq.html#generate-images-without-having-a-window-appear for more details.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. In cases where you've X11 connection rejected, wrong authentication... The second option can quite useful.
The second solution worked to me when trying to use matplotlib in a cgi.
The second solution also helped me out a lot when trying to get things to work on windows.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.