AttributeError: module 'community' has no attribute 'best_partition'

Viewed 1409
2 Answers

If still useful, this worked out for me :

pip uninstall community
pip install python-louvain

I could import community afterwards and use best_partition.

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:

enter image description here

Related