Reputation: 11
I am trying to use networkx to do community analysis.
The error I am getting is module 'networkx.algorithms.community' has no attribute 'girvan_newman'
.
My python version is 3.6, with networkx version 2.0.
Here is my code:
import networkx as nx
from networkx.algorithms import community
G = nx.barbell_graph(5, 1)
communities_generator = community.girvan_newman(G)
top_level_communities = next(communities_generator)
next_level_communities = next(communities_generator)
sorted(map(sorted, next_level_communities))
Upvotes: 1
Views: 4550
Reputation: 1
This worked for me
from networkx.algorithms.community.centrality import girvan_newman
communities_generator = community.centrality.girvan_newman(G)
EDIT: by importing community.centrality.girvan_newman(G) instead of community.girvan_newman(G) is the key here
Upvotes: 0
Reputation: 2493
The function you're looking for is in a slightly different namespace from what you have. You'll need to import it as follows:
from networkx.algorithms.community.centrality import girvan_newman
Note the centrality
part of the namespace that was missing.
Upvotes: 2