How To Run Neato From Pygraphviz On Windows
Solution 1:
I had the same problem. Here's what I did in case anyone else is struggling to get pygraphvis working on Windows.
First off, I installed graphviz. I tried to install pygraphvis thrugh pip, but it refused to work. Eventually, I found the unofficial Windows binaries, so I installed that. Importing the module now works, but calling G.layout()
led to the above error.
Calling neato -V
worked, so it was on my PATH. I figured out that the problem was that python was running in a command prompt that was created prior to installing pygraphvis, so PATH wasn't updated. Restarting the command prompt fixed this, but led to a new error, something about C:\Program
not being a valid command.
I figured that pygraphvis was probably failing to quote the path correctly, meaning it cuts off at the space in Program Files. I solved the problem by symlinking it to a path without spaces.
mklink /d C:\ProgramFilesx86 "C:\Program Files (x86)"
Note that this must be run in admin mode. You can do it by going to the start menu, typing in cmd, and then hitting Ctrl+shift+enter.
After this, I edited my PATH to refer to the symlink, restarted cmd, and everything worked.
Solution 2:
The problem is that pygraphviz call an external program, a part of the graphviz suite called neato, to draw the graph. What is happening is that you doesn't have graphviz installed and when python try to call it it complains about not finding it. Actually pygraphviz is just a wrapper that gives you the possibility to call graphviz from inside python, but per se doesn't do anything and doesn't install graphviz by default.
The easiest solution is to try a different solution for the plot instead of neato. the accepted option are:
neato
dot
twopi
circo
fdp
nop
try one of those and see if one of them works. Otherwise you can install graphviz, that will give you the required program. It's and open-source program available on every platform, so it shouldn't be a problem to install it.
see at http://www.graphviz.org/
If you simply need to have a sketch of the graph you can use the networkx.draw function on a networkx graph, that uses matplotlib to create an interactive plot.
import networkx as nxG= G=nx.from_numpy_matrix(A)
nx.draw(G)
Solution 3:
Your problem is that neato
is missing.
neato
is part of the graphviz suite which you can install on your PC e.g. from here. (I used the .msi
)
Now neato is "installed", but your system does not know where. So add the directory where neato.exe
is contained in to your PATH
environment variable. On Win10, this can be done with Start -> Edit environment variables for your account -> select path in the upper window -> edit -> New -> C:\Program Files (x86)\Graphviz2.38\bin\
or whatever your install directory is.
Solution 4:
There is probably more than one cause for this error, but if it is caused by a missing path to the graphviz modules [neato,dot,twopi,circo,fdp,nop]
, then there is one hack that worked for me. I'm currently asking what the correct solution is, but you can use this
ifnot'C:\\Program Files (x86)\\Graphviz2.38\\bin'inos.environ["PATH"]:
os.environ["PATH"] += os.pathsep + 'C:\\Program Files (x86)\\Graphviz2.38\\bin'
at the beginning of your script. To generalize, if your graphviz files are saved somewhere else:
graph_path='your_bin_folder_path'ifnot graph_path inos.environ["PATH"]:
os.environ["PATH"] += os.pathsep + graph_path
In particular, this worked on windows 10, using anaconda navigator and python version 3.7.
Solution 5:
Try something like this to see where pygraphviz thinks your external programs are:
# Get paths of graphviz programsimport pygraphviz as pgv
A = pgv.AGraph()
progs_list = ['neato', 'dot', 'twopi', 'circo', 'fdp', 'nop', 'wc', 'acyclic', 'gvpr',
'gvcolor', 'ccomps', 'sccmap', 'tred', 'sfdp', 'unflatten']
for prog in progs_list:
try:
runprog = A._get_prog(prog)
print(f'{runprog}')
except ValueError as e:
print(f'{prog} gets this error: {str(e).strip()}')
After looking at the results, it's a lot of work outside your IDE installing Graphviz and setting up your Path environmental variable in the System control panel, etc.
Post a Comment for "How To Run Neato From Pygraphviz On Windows"