显然没有导入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'

最佳答案

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

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

一个简单的解决方案:您可以转到找到的文档(请注意url中的“开发”)。然后从那里复制命令并将其粘贴到您的版本中。您可以通过help(nx.dag)查找版本所在的位置。您需要从复制粘贴中删除“ [doc]”部分,您必须编辑__all__部分,并且必须删除@not_implemented_for命令。

关于python - 缺少python方法NetworkX,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30330887/

10-09 08:27
查看更多