2014-10-02 64 views
0

當我嘗試在我的代碼中使用graphviz_layout方法時收到錯誤「InvocationException:找不到GraphViz的可執行文件,找不到GraphViz的可執行文件」。當graphviz_layout被spring_layout替換時,代碼工作正常。從返回異常信息看起來它調用pydot_layout。我通過Canopy的包管理器安裝了pydot模塊,但是導入它並沒有幫助。我也安裝graphviz安裝並導入它沒有運氣。在iPython筆記本中從NetworkX調用GraphViz佈局時出現「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 

系統信息:我使用的是最新版本,並Enthought冠層模塊的64位Mac上與OS X 10.9.5。另外,我正在使用iPython筆記本。

回答

1

我解決了這個由我的Mac上使用的MacPorts安裝GraphViz的:

sudo port install graphviz 

安裝Python包是不夠的,在這種情況下。儘管如此,這是Enthought應該採取的依賴。

0

通常情況下,你應該有一個新安裝的MacPorts的開始

  1. 刪除舊的MacPorts

    -f卸載安裝
    sudo的港口清潔 - 共同努力--archive所有

  2. sudo的端口

  3. 導入,安裝並編譯最近的Macports源文件

    CD〜
    捲曲-O https://distfiles.macports.org/MacPorts/MacPorts-2.3.3.tar.bz2
    焦油XF的MacPorts-2.3.3.tar.bz2
    CD的MacPorts-2.3.3/
    的./configure
    使
    須藤使安裝
    港版

  4. (可選)更新的MacPorts

    須藤端口自更新
    須藤端口upgrad Ë過時

  5. 使用新鮮的MacPorts

    sudo的港口安裝graphviz的安裝Graphviz的
    須藤PIP安裝--upgrade graphviz的