Reputation: 880
I try to run this code:
from cdlib import algorithms
import networkx as nx
G = nx.karate_club_graph()
coms = algorithms.louvain(G, resolution=1., randomize=False)
but the error remains the same. I have tried all options given by AttributeError: module 'networkx.algorithms.community' has no attribute 'best_partition'
but it doesn't work.
Also, I'm working in Google Colab and I have installed cdlib.
Upvotes: 5
Views: 4763
Reputation: 76
If still useful, this worked out for me :
pip uninstall community
pip install python-louvain
I could import community
afterwards and use best_partition
.
Upvotes: 2
Reputation: 4705
From this, it looks like there is a community
python package that conflicts with the python-louvain
package. Both packages happen to be pre-installed in google colab kernels. To avoid this conflict, I just uninstalled networkx
, python-louvain
and community
and then reinstalled networkx
and python-louvain
. Finally I installed cdlib.
After that I ran your code and everything worked well. So overall the code is:
!pip uninstall networkx
!pip uninstall python-louvain
!pip uninstall community
!pip install python-louvain
!pip install networkx
!pip install cdlib
from cdlib import algorithms
import networkx as nx
G = nx.karate_club_graph()
coms = algorithms.louvain(G, resolution=1., randomize=False)
print(coms)
And the ouput gives:
Upvotes: 3