graph-lib
raw JSON → 0.4.8 verified Fri May 01 auth: no python
A set of diffusion related graph algorithms for Python, including community detection, node ranking, and graph sampling. Current version 0.4.8. Low release cadence.
pip install graph-lib Common errors
error ModuleNotFoundError: No module named 'graphlib' ↓
cause Trying to import as 'graphlib' which is a stdlib module. The correct import uses underscore: 'graph_lib'.
fix
pip install graph-lib and then import graph_lib (with underscore).
error TypeError: unsupported operand type(s) for +: 'int' and 'list' ↓
cause Passing non-integer node labels that cause internal conversion errors.
fix
Relabel nodes to integers: G = nx.convert_node_labels_to_integers(G)
error AttributeError: module 'graph_lib' has no attribute 'diffusion_map' ↓
cause diffusion_map was removed/deprecated in newer versions. Use spectral_embedding instead.
fix
Use graph_lib.spectral_embedding(G, n_components=None) instead.
Warnings
deprecated Function 'graph_lib.diffusion_map' has been deprecated in v0.4.0. Use 'graph_lib.spectral_embedding' instead. ↓
fix Replace graph_lib.diffusion_map(G) with graph_lib.spectral_embedding(G, n_components=None)
gotcha The package imports as 'graph_lib' (underscore), not 'graphlib'. Importing 'graphlib' silently imports Python's stdlib module which does not raise an error but gives wrong results. ↓
fix Use 'import graph_lib' or 'from graph_lib import ...'
gotcha Graph algorithms expect node labels to be integers. Non-integer labels may cause silent type errors in internal matrix construction. ↓
fix Ensure node labels are integers, e.g., G = nx.convert_node_labels_to_integers(G)
Imports
- graph_lib wrong
import graphlibcorrectimport graph_lib
Quickstart
import graph_lib
import networkx as nx
G = nx.karate_club_graph()
communities = graph_lib.spectral_partitioning(G, k=2)
print(communities)