To build and install run from source
python setup.py install
You can also install from pip with
pip install python-louvain
The package name on pip is python-louvain but it is imported as community in python. You will find documentation about this module at http://python-louvain.readthedocs.io/
To use as a python library
import community as community_louvain
import networkx as nx
import matplotlib.pyplot as plt
# Replace this with your networkx graph loading depending on your format !
G = nx.erdos_renyi_graph(30, 0.05)
#first compute the best partition
partition = community_louvain.best_partition(G)
#drawing
size = float(len(set(partition.values())))
pos = nx.spring_layout(G)
count = 0.
for com in set(partition.values()) :
count = count + 1.
list_nodes = [nodes for nodes in partition.keys()
if partition[nodes] == com]
nx.draw_networkx_nodes(G, pos, list_nodes, node_size = 20,
node_color = str(count / size))
nx.draw_networkx_edges(G, pos, alpha=0.5)
plt.show()
There is also a command line
$ community <filename>
filename is a binary file as generated by the convert utility distributed with the C implementation at https://sites.google.com/site/findcommunities/ This is mostly for debugging purpose and I advise to use this module more as a library with your graph loading code than with this command.
You can find documentation at https://python-louvain.readthedocs.io/
To generate documentation run
pip install numpydoc sphinx
cd docs
make
To run tests
pip install nose
python setup.py test