Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib - Python Error

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.

like image 615
user1816896 Avatar asked Nov 12 '12 00:11

user1816896


People also ask

Why is matplotlib not working in Python?

Matplotlib is not a built-in module (it doesn't come with the default python installation) in Python, you need to install it explicitly using the pip installer and then use it. If you looking at how to install pip or if you are getting an error installing pip checkout pip: command not found to resolve the issue.

Does Python 3.9 support matplotlib?

BUILDING MATPLOTLIB matplotlib: yes [3.3. 2] python: yes [3.9.

Why can I not import matplotlib?

The most frequent source of this error is that you haven't installed matplotlib explicitly with pip install matplotlib . Alternatively, you may have different Python versions on your computer, and matplotlib is not installed for the particular version you're using.

Why does matplotlib say no module?

The Python "ModuleNotFoundError: No module named 'matplotlib'" occurs when we forget to install the matplotlib module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install matplotlib command.


1 Answers

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.

like image 151
James Beilby Avatar answered Sep 20 '22 04:09

James Beilby