21

I have the following problem: I am on xUbuntu OS and I am trying to use networkx in a Flask application, and I am having the following code:

.....
import networkx as nx
......
# Creating and initializing graph object which is networkx object
hosts_graph = get_networkx_graph_object()

# Variable 'coord' where the coordinates for each node will be stored
coord = nx.pygraphviz_layout(hosts_graph, prog = 'dot')

The last line is line 411. I get the following error:

File "/home/kiril/Documents/workfolder/omeganoc-sprint/onoc/omeganoc/grapher.py", line 411, in grouping_method
    coord = nx.pygraphviz_layout(hosts_graph, prog = 'dot')
  File "/usr/local/lib/python2.7/dist-packages/networkx-1.7-py2.7.egg/networkx/drawing/nx_agraph.py", line 264, in pygraphviz_layout
    A.layout(prog=prog,args=args)
  File "/usr/local/lib/python2.7/dist-packages/pygraphviz-1.1-py2.7-linux-x86_64.egg/pygraphviz/agraph.py", line 1301, in layout
    data=self._run_prog(prog,' '.join([args,"-T",fmt]))
  File "/usr/local/lib/python2.7/dist-packages/pygraphviz-1.1-py2.7-linux-x86_64.egg/pygraphviz/agraph.py", line 1248, in _run_prog
    runprog=self._get_prog(prog)
  File "/usr/local/lib/python2.7/dist-packages/pygraphviz-1.1-py2.7-linux-x86_64.egg/pygraphviz/agraph.py", line 1236, in _get_prog
    raise ValueError("Program %s not found in path."%prog)
ValueError: Program dot not found in path.

What could be causing this problem? I've installed networkx and pygraphviz, but I still get this error. Any ideas how to solve this problem?

Belphegor
  • 4,456
  • 11
  • 34
  • 59

5 Answers5

35

PyGraphviz doesn't work without Graphviz. Install that too.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • 2
    You may also get this problem even if you have PyGraphviz installed, if the PyGraphviz bin directory has not been added to the path - I had this problem on windows. – Lee Jan 11 '16 at 14:00
  • 4
    Note - graphviz has to be installed system wide using the mechanism for your OS, installing via pip doesn't work. – SteveJ Sep 03 '19 at 18:10
  • @SteveJ what if I'm doing this in a virtual environment of anaconda? – Bowen Liu Nov 09 '22 at 21:27
8

If you have Anaconda installed the simplest way to go about this is to run the following from CMD:

conda install pydot-ng

and:

conda install graphviz

This takes care of adding dot to the path.

chrki
  • 6,143
  • 6
  • 35
  • 55
Anon
  • 619
  • 1
  • 9
  • 18
7

Make sure Graphviz is installed through the Windows installer (can be downloaded from http://www.graphviz.org/Download_windows.php).

Then add the path of the bin fold to the system variable "Path". It is "dot.exe" in bin fold that is looked for by pygraphviz.

It does not work if you pip install graphviz.

user6107173
  • 589
  • 5
  • 6
3

Had a similar issue on Debian GNU/Linux, it gone after i install this:

apt install graphviz
apt install graphviz-dev

After this you can check that it works with

dot -V

You'll get responce like this dot - graphviz version 2.43.0 (0) if problem is fixed

weAreStarsDust
  • 2,634
  • 3
  • 10
  • 22
1

In SUSE linux:

sudo zypper install graphviz

might help.

Susa
  • 361
  • 4
  • 9