NetworkX

raw JSON →
3.6.1 verified Tue May 12 auth: no python install: verified quickstart: stale

NetworkX is a Python package for creating and manipulating graphs and networks. The current version is 3.6.1, released on 2025-12-15, with a release cadence of approximately every 6 months.

pip install networkx
error ModuleNotFoundError: No module named 'networkx'
cause The NetworkX library is not installed in the current Python environment or the environment is not correctly activated.
fix
Run pip install networkx in your terminal or command prompt. If using Anaconda, use conda install networkx instead.
error AttributeError: module 'networkx' has no attribute 'info'
cause The `info()` method was removed in NetworkX 3.0.0; direct attribute access or other specific functions should be used instead for graph summaries.
fix
Access graph properties directly (e.g., G.number_of_nodes(), G.number_of_edges()) or print the graph object print(G) for a basic summary. If a detailed summary is needed for compatibility with older code, consider nx.graph_info(G) if available, or update the code to use newer API features.
error AttributeError: module 'networkx' has no attribute 'from_pandas_edgelist'
cause The `from_pandas_edgelist` function was introduced in NetworkX version 2.0.0. This error occurs when using an older version of the library.
fix
Upgrade NetworkX to version 2.0 or newer by running pip install --upgrade networkx in your terminal or command prompt.
error networkx.exception.NetworkXError: Edge tuple ('A',) must be a 2-tuple or 3-tuple.
cause This error occurs when the `add_edges_from()` method receives an iterable where individual elements are not valid 2-tuples (source, target) or 3-tuples (source, target, data_dict) representing edges.
fix
Ensure the input to add_edges_from is a list or iterable of tuples, where each tuple strictly contains two (source, target) or three elements (source, target, edge_attributes), e.g., G.add_edges_from([(1, 2), (2, 3, {'weight': 0.5})]).
error SyntaxError: invalid syntax (when running `pip install networkx`)
cause The `pip install` command is being executed within the Python interpreter's interactive shell, not directly in the system's command prompt or terminal.
fix
Exit the Python interpreter (by typing exit() and pressing Enter) and then run pip install networkx directly in your operating system's command prompt (Windows) or terminal (macOS/Linux).
breaking The 'release' module has been removed in NetworkX 3.0. Direct import of 'release' will result in an ImportError.
fix Remove the import statement 'from networkx import release' from your code.
deprecated The 'add_path' function is now a method of the Graph class and should be called on a Graph instance.
fix Replace 'networkx.add_path(G, [0, 1, 2, 3])' with 'G.add_path([0, 1, 2, 3])'.
gotcha Ensure that all optional dependencies (numpy, scipy, matplotlib, pandas) are installed for full functionality, especially for graph visualization and advanced computations.
fix Install optional dependencies using 'pip install networkx[default]'.
python os / libc status wheel install import disk
3.10 alpine (musl) - - 0.42s 32.0M
3.10 slim (glibc) - - 0.33s 32M
3.11 alpine (musl) - - 0.56s 38.2M
3.11 slim (glibc) - - 0.45s 39M
3.12 alpine (musl) - - 0.48s 29.2M
3.12 slim (glibc) - - 0.48s 30M
3.13 alpine (musl) - - 0.42s 28.7M
3.13 slim (glibc) - - 0.42s 29M
3.9 alpine (musl) - - 0.33s 30.9M
3.9 slim (glibc) - - 0.27s 31M

A simple example to create a graph, add nodes and edges, and visualize it using matplotlib.

import networkx as nx

# Create an empty graph
G = nx.Graph()

# Add nodes and edges
G.add_nodes_from([1, 2, 3])
G.add_edges_from([(1, 2), (2, 3)])

# Draw the graph
import matplotlib.pyplot as plt
nx.draw(G, with_labels=True)
plt.show()