Notebook中从NetworkX调用GraphViz布局时

Notebook中从NetworkX调用GraphViz布局时

本文介绍了错误“未找到GraphViz的可执行文件";在iPython Notebook中从NetworkX调用GraphViz布局时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码中尝试使用方法graphviz_layout时收到错误消息"InvocationException:找不到GraphViz的可执行文件,找不到GraphViz的可执行文件错误".将graphviz_layout替换为spring_layout时,代码可以正常工作.从回退异常信息来看,它看起来像是pydot_layout.我已经通过Canopy的软件包管理器安装了pydot模块,但是导入它并没有帮助.我还安装了graphviz并没有运气就将其导入.

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.

这是我的代码:

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笔记本.

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.

推荐答案

我通过使用Macport在Mac上安装GraphViz来解决了这个问题:

I solved this by installing GraphViz on my Mac using macports:

sudo port install graphviz

在这种情况下,仅安装python软件包是不够的.尽管如此,这是Enthought应该处理的依赖项.

Installing python packages is not enough in this case. Nonetheless, this is a dependency that should have been taken of by Enthought.

这篇关于错误“未找到GraphViz的可执行文件";在iPython Notebook中从NetworkX调用GraphViz布局时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 11:58