How to Install networkx in Python

v3.6.1 Data & Science Python !=3.14.1,>=3.11

Python package for creating and manipulating graphs and networks

Install pip install networkx

What is networkx?

Python package for creating and manipulating graphs and networks

NetworkX is a Python package for the creation, manipulation, and study of the structure, dynamics, and functions of complex networks.

Find the shortest path between two nodes in an undirected graph:

>>> import networkx as nx >>> G = nx.Graph() >>> G.addedge("A", "B", weight=4) >>> G.addedge("B", "D", weight=2) >>> G.addedge("A", "C", weight=3) >>> G.addedge("C", "D", weight=4) >>> nx.shortestpath(G, "A", "D", weight="weight") ['A', 'B', 'D']

Quick Start

Minimal example to get started with networkx:

import networkx as nx

G = nx.Graph()
G.add_edges_from([(1, 2), (1, 3), (2, 4), (3, 4), (4, 5)])
print(f"Nodes: {G.number_of_nodes()}")  # 5
print(f"Edges: {G.number_of_edges()}")  # 5
print(nx.shortest_path(G, 1, 5))       # [1, 2, 4, 5]

Installation

pip (standard)

pip install networkx

Virtual environment (recommended)

python -m venv venv
source venv/bin/activate   # Windows: venv\Scripts\activate
pip install networkx

pip3

pip3 install networkx

conda

conda install -c conda-forge networkx

Poetry

poetry add networkx

Verify the Installation

After installing, confirm the package is available:

python -c "import networkx; print(networkx.__version__)"

If this prints a version number, installation succeeded. If you see a ModuleNotFoundError, see the errors section below.

Installation Errors

Common errors when installing networkx with pip.

ModuleNotFoundError: No module named 'networkx'

Cause: The package is not installed in the current Python environment.

Fix: Run pip install networkx. If using a virtual environment, ensure it is activated first.

ModuleNotFoundError: No module named 'networkx' (installed but still failing)

Cause: pip installed the package into a different Python than the one running your script.

Fix: Use python -m pip install networkx to install into the interpreter you are running.

ImportError: cannot import name 'X' from 'networkx'

Cause: The function or class does not exist in the installed version.

Fix: Check the version with pip show networkx and upgrade with pip install --upgrade networkx.

pip: command not found

Cause: pip is not in PATH or Python was not added to PATH during installation.

Fix: Try python -m pip install networkx. On macOS/Linux try pip3.

PermissionError: [Errno 13] Permission denied

Cause: No write access to the system Python package directory.

Fix: Use a virtual environment, or add --user: pip install --user networkx

SSL: CERTIFICATE_VERIFY_FAILED

Cause: pip cannot verify PyPI's SSL certificate — common behind corporate proxies.

Fix: Try: pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org networkx

MemoryError when loading data

Cause: Dataset is too large to fit in RAM.

Fix: Read in chunks, filter columns on load, or consider Polars/Dask for out-of-core processing.

Recent Releases

VersionReleased
3.6.1 latest 2025-12-08
3.6 2025-11-24
3.6rc0 2025-11-04
3.5 2025-05-29
3.5rc0 2025-05-09

Full release history on PyPI →

Manage networkx

Upgrade to latest version

pip install --upgrade networkx

Install a specific version

pip install networkx==3.6.1

Uninstall

pip uninstall networkx

Check what is installed

pip show networkx

Last updated: 2026-04-11 • Data from PyPI