显然,NetworkX附带的许多方法似乎都没有导入。例如,根据网站,我应该可以使用:
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'
答案 0 :(得分:1)
您正在使用的命令在开发版本中似乎是新的。这是dag
命令的当前文档:
https://networkx.github.io/documentation/latest/reference/algorithms.dag.html
一个简单的解决方案:您可以转到您找到的文档(请注意网址中的"开发和#34;)。然后将命令从那里复制并粘贴到您的版本中。您可以在help(nx.dag)
找到您的版本所在的位置。您需要从复制粘贴中删除一些部分,说明" [doc]",您必须编辑__all__
部分,然后您就可以了必须删除@not_implemented_for
命令。