问题
I received the error "InvocationException: GraphViz's executables not found, error GraphViz's executables not found" when trying to use the method graphviz_layout in my code. The code works fine when graphviz_layout is replaced by spring_layout. From the throwback exception information, it looks like it calls pydot_layout. I have the pydot module installed through Canopy's package manager, but importing it does not help. I have also pip installed graphviz and imported it with no luck.
Here is my code:
import networkx as nx
import matplotlib.pyplot as plt
keywordTreeFile = open('decode_wordnet/keywordTreeFile.TXT','r') #keyword generation file
keywordTreeFileLineData = keywordTreeFile.readlines()
G = nx.Graph()
pairData = []
for i in range(0,len(keywordTreeFileLineData)):
pairData = pairData + [keywordTreeFileLineData[i].split('\t')]
pairData[i][1] = pairData[i][1].rstrip('\n')
G.add_edge(pairData[i][0],pairData[i][1])
pos = nx.graphviz_layout(G)
nx.draw(G,
pos=pos,
width = 1.0,
with_labels = True,
font_size = 3,
linewidths=.1
)
plt.savefig("graph.pdf")
Here is the throwback exception information:
---------------------------------------------------------------------------
InvocationException Traceback (most recent call last)
<ipython-input-1-e85a11cf6191> in <module>()
15
16 #pos = nx.spring_layout(G,k=.15,iterations=50,scale=100)
---> 17 pos = nx.graphviz_layout(G)
18 #labels = nx.draw_networkx_labels(G,pos)
19 nx.draw(G,
/Users/scott/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/networkx/drawing/nx_pydot.pyc in graphviz_layout(G, prog, root, **kwds)
245 This is a wrapper for pydot_layout.
246 """
--> 247 return pydot_layout(G=G,prog=prog,root=root,**kwds)
248
249
/Users/scott/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/networkx/drawing/nx_pydot.pyc in pydot_layout(G, prog, root, **kwds)
269 P.set("root",make_str(root))
270
--> 271 D=P.create_dot(prog=prog)
272
273 if D=="": # no data returned
/Users/scott/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pydot.pyc in <lambda>(f, prog)
1800 self.__setattr__(
1801 'create_'+frmt,
-> 1802 lambda f=frmt, prog=self.prog : self.create(format=f, prog=prog))
1803 f = self.__dict__['create_'+frmt]
1804 f.__doc__ = '''Refer to the docstring accompanying the 'create' method for more information.'''
/Users/scott/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pydot.pyc in create(self, prog, format)
1951 if self.progs is None:
1952 raise InvocationException(
-> 1953 'GraphViz\'s executables not found' )
1954
1955 if not self.progs.has_key(prog):
InvocationException: GraphViz's executables not found
System information: I am using the lastest version and modules of Enthought Canopy on a 64-bit Mac with OS X 10.9.5. Also, I am using an iPython notebook.
回答1:
I solved this by installing GraphViz on my Mac using macports:
sudo port install graphviz
Installing python packages is not enough in this case. Nonetheless, this is a dependency that should have been taken of by Enthought.
回答2:
Often, you should start with a fresh installation of Macports
Remove old Macports
sudo port -f uninstall installed
sudo port clean --work --archive allImport, install and compile recent Macports sources files
cd ~
curl -O https://distfiles.macports.org/MacPorts/MacPorts-2.3.3.tar.bz2
tar xf MacPorts-2.3.3.tar.bz2
cd MacPorts-2.3.3/
./configure
make
sudo make install
port version(Optional) update Macports
sudo port selfupdate
sudo port upgrade outdatedInstall Graphviz using your fresh Macports
sudo port install graphviz
sudo pip install --upgrade graphviz
回答3:
For ubuntu users:-
sudo apt-get install -y graphviz libgraphviz-dev
This installs the graphviz executables needed by python to display plots
来源:https://stackoverflow.com/questions/26153413/error-graphvizs-executables-not-found-when-calling-graphviz-layout-from-netwo