NetworKit
raw JSON → 11.2.1 verified Fri May 01 auth: no python
NetworKit is an open-source toolbox for high-performance network analysis. It provides efficient implementations of graph algorithms for large networks, with a focus on scalability and performance. Current version 11.2.1, released irregularly.
pip install networkit Common errors
error ModuleNotFoundError: No module named 'networkit' ↓
cause NetworKit not installed or installed in wrong environment.
fix
Run 'pip install networkit'. Ensure you are using the correct Python environment.
error AttributeError: module 'networkit' has no attribute 'graph' ↓
cause Trying to access submodule directly without importing it.
fix
Use 'from networkit import graph' or 'import networkit.graph' (though the latter may still fail in some versions). Preferred: 'from networkit import graph'.
error ImportError: cannot import name 'BFS' from 'networkit' ↓
cause BFS is not a top-level attribute; it's in the 'distance' submodule.
fix
Use 'from networkit.distance import BFS'.
Warnings
breaking In version 10.0, the module structure was reorganized. Submodules like 'graph' and 'distance' must be imported explicitly (e.g., 'from networkit import graph') instead of 'import networkit.graph'. ↓
fix Use 'from networkit import <submodule>' instead of 'import networkit.<submodule>'.
breaking Starting with version 9.0, Python 3.6 and 3.7 are no longer supported. Requires Python >=3.8 (now >=3.10 as of 11.0). ↓
fix Ensure Python version >=3.10.
deprecated The old 'NetworKit' C++ naming is deprecated in Python. Do not use 'from NetworKit import Graph'. ↓
fix Use 'import networkit as nk' and 'nk.Graph'.
gotcha Graph edges are directed by default? Actually, Graph is undirected by default. Use Graph(0, directed=True) for directed graphs. ↓
fix Specify directed=True when creating a directed graph.
Imports
- networkit wrong
import NetworKitcorrectimport networkit as nk - graph wrong
import networkit.graphcorrectfrom networkit import graph
Quickstart
import networkit as nk
# Create a graph
G = nk.Graph(5)
G.addEdge(0, 1)
G.addEdge(1, 2)
G.addEdge(2, 3)
G.addEdge(3, 4)
# Run BFS
bfs = nk.distance.BFS(G, 0)
bfs.run()
print(bfs.distances())