0 votes
1 view
in Python by (45.2k points)

I am trying to use networkx with Python. When I run this program it get this error. Is there anything missing?

#!/usr/bin/env python

import networkx as nx

import matplotlib

import matplotlib.pyplot

import matplotlib.pyplot as plt





#nx_write_dot(G, 'node.png')



Traceback (most recent call last):

  File "graph.py", line 13, in <module>


  File "/usr/lib/pymodules/python2.5/networkx/drawing/nx_pylab.py", line 124, in draw


  File "/usr/lib/pymodules/python2.5/matplotlib/pyplot.py", line 276, in gcf

    return figure()

  File "/usr/lib/pymodules/python2.5/matplotlib/pyplot.py", line 254, in figure


  File "/usr/lib/pymodules/python2.5/matplotlib/backends/backend_tkagg.py", line 90, in new_figure_manager

    window = Tk.Tk()

  File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 1650, in __init__

    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)

_tkinter.TclError: no display name and no $DISPLAY environment variable

1 Answer

0 votes
by (16.8k points)

The main problem is that (on your system) matplotlib chooses an x-using backend by default. I just had the same problem on one of my servers. The solution for me was to add the following code in a place that gets read before any other pylab/matplotlib/pyplot import:

import matplotlib

# Force matplotlib to not use any Xwindows backend.


The alternative is to set it in your .matplotlibrc

Welcome to Intellipaat Community. Get your technical queries answered by top developers !