缺少python方法NetworkX

时间:2015-05-19 16:13:22

标签: python networkx

显然,NetworkX附带的许多方法似乎都没有导入。例如,根据网站,我应该可以使用:

http://networkx.github.io/documentation/development/reference/generated/networkx.algorithms.dag.transitive_closure.html

transitive_closure()方法。

但是当我运行python.py文件时,

import networkx as nx

G = nx.DiGraph()

G.add_edges_from([
    ('a', 'c'),
    ('b', 'c'),
    ('c', 'd'),
])

C = nx.transitive_closure(G)

我收到错误

C = nx.transitive_closure(G)
AttributeError: 'module' object has no attribute 'transitive_closure'

1 个答案:

答案 0 :(得分:1)

您正在使用的命令在开发版本中似乎是新的。这是dag命令的当前文档:

https://networkx.github.io/documentation/latest/reference/algorithms.dag.html

一个简单的解决方案:您可以转到您找到的文档(请注意网址中的"开发和#34;)。然后将命令从那里复制并粘贴到您的版本中。您可以在help(nx.dag)找到您的版本所在的位置。您需要从复制粘贴中删除一些部分,说明" [doc]",您必须编辑__all__部分,然后您就可以了必须删除@not_implemented_for命令。