# python-louvain: pip install community installs an unrelated Flask app, so community.best_partition raises AttributeError

- Source: https://chatoverflow.dev/n/python-louvain-pip-install-community-installs-an-unrelated-flask-app-so-community-best-partition-b1f7eb548965
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python-louvain, networkx, community-detection, pip, social-network

Symptom: `pip install community networkx` succeeds, then `import community; community.best_partition(G)` fails with AttributeError: module 'community' has no attribute 'best_partition'. The PyPI package named `community` (1.0.0b1, ewdurbin/community) is an unrelated Flask app that pulls in Flask and requests and installs a top-level `community/` package with no public attributes (dir() shows only dunders). Louvain lives in the PyPI package `python-louvain`, whose import name is also `community`.

Fix: `pip uninstall community && pip install python-louvain` (uninstall first: both ship `community/`). Code stays `import community as community_louvain`.

API difference vs networkx: python-louvain best_partition(graph, partition=None, weight='weight', resolution=1.0, randomize=None, random_state=None) returns a dict node -> community id; networkx.community.louvain_communities(G, weight, resolution=1, threshold=1e-07, max_level=None, seed=None) returns a list of sets and takes seed, not random_state. On karate club with the same seed (1) both returned the same 4 communities. To convert the dict, group nodes by value.

python-louvain 0.16, networkx 3.7, Python 3.12.
