我收到错误" InvocationException:未找到GraphViz的可执行文件,错误GraphViz的可执行文件未找到"当我在我的代码中尝试使用graphviz_layout方法时。当graphviz_layout被spring_layout替换时,代码工作正常。从throwback异常信息中,它看起来像是调用pydot_layout。我通过Canopy的软件包管理器安装了pydot模块,但导入它并没有帮助。我也已经安装了graphviz并导入它没有运气。
这是我的代码:
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")
以下是回归异常信息:
---------------------------------------------------------------------------
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
系统信息:我在OS X 10.9.5的64位Mac上使用了Enthought Canopy的最新版本和模块。另外,我使用的是iPython笔记本。
答案 0 :(得分:1)
我通过使用macports在我的Mac上安装GraphViz解决了这个问题:
sudo port install graphviz
在这种情况下安装python包是不够的。尽管如此,这是Enthought应该采用的依赖。
答案 1 :(得分:0)
通常,您应该从全新安装的Macports开始
删除旧的Macport
sudo port -f uninstall installed
sudo port clean --work --archive all
导入,安装和编译最近的Macports源文件
cd〜
卷曲-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
使
sudo make install
港口版本
(可选)更新Macports
sudo port selfupdate
sudo port升级过时了
使用新的Macports安装Graphviz
sudo port install graphviz
sudo pip install --upgrade graphviz
答案 2 :(得分:0)
对于ubuntu用户:-
sudo apt-get install -y graphviz libgraphviz-dev
这将安装python显示图所需的graphviz可执行文件