max(nx.connected_component_subgraphs(),) 错误,没有属性“connected_component_subgraphs”

Pra*_*ija 2 python networkx tweepy

我正在尝试运行这段代码:

graph = nx.Graph()

largest_subgraph = max(nx.connected_component_subgraphs(graph), key=len)
Run Code Online (Sandbox Code Playgroud)

但我收到此错误消息:

AttributeError: module 'networkx' has no attribute 'connected_component_subgraphs'
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

Jes*_*per 7

Connected_Component_subgraphs() 已从版本 2.4 中删除。

相反,使用这个:

graph = nx.Graph()

connected_component_subgraphs = (graph.subgraph(c) for c in nx.connected_components(graph))

largest_subgraph = max(connected_component_subgraphs, key=len)
Run Code Online (Sandbox Code Playgroud)

根据这个答案