Featured Article

Install NetworkX in Python: Step-by-Step Guide

Kenneth Jul 13, 2026

Installing the NetworkX library in Python is a straightforward process that enables you to work with graphs, nodes, edges, and more using a powerful and easy-to-use Python library. NetworkX is crucial for numerous data science and network analysis tasks. Here's a step-by-step guide to help you get started.

Installing Python on Linux
Installing Python on Linux

Before we dive in, ensure you have Python 3 installed on your system. NetworkX is compatible with Python 2.7 and later, but using Python 3 is recommended due to its improved performance and features.

Installing Python on Ubuntu
Installing Python on Ubuntu

Installing NetworkX via pip

pip is a package manager for Python. It's the most common and easiest way to install packages, including NetworkX.

Python Kivy Projects
Python Kivy Projects

Open your command line or terminal and type the following command to install NetworkX:

pip install networkx

If you're using the Jupyter notebook, run the command in a cell by prefixing it with an exclamation mark:

Practical Social Network Analysis with Python - PYOFLIFE
Practical Social Network Analysis with Python - PYOFLIFE

!pip install networkx

Once the installation is complete, you can import NetworkX in your Python script or interactive shell by simply typing:

import networkx

You can verify the successful installation by checking the version with:

print(networkx.__version__)

Using Python's built-in package manager

How to Install Python on Windows - Beginner friendly
How to Install Python on Windows - Beginner friendly

Python includes a package manager in its standard library called ensurepip. You can use it to install NetworkX. Here's how:

Aktivieren Sie den built-in package manager first by running:

python -m ensurepip --upgrade

Then install NetworkX with:

Learn Ethical Hacking with Python🔐
Learn Ethical Hacking with Python🔐

pip install networkx

ensurepip is a good option if you prefer to use Python's built-in tools only or if you experience any issues with pip.

Installing NetworkX from source

the text 5 python networking projects every develoer should build on blue background with white lines
the text 5 python networking projects every develoer should build on blue background with white lines
Python Network Automation Training changes today!
Python Network Automation Training changes today!
All Important Python Functions for Beginners (Complete Cheat Sheet)
All Important Python Functions for Beginners (Complete Cheat Sheet)
How to Use the String join() Method in Python
How to Use the String join() Method in Python
an image of linux with the text fast pipp alternative
an image of linux with the text fast pipp alternative
How to Set Up Python the Right Way (2025 Beginner Guide)
How to Set Up Python the Right Way (2025 Beginner Guide)
20 Python Functions You Should Know
20 Python Functions You Should Know
Python Conditional Statements & Loops
Python Conditional Statements & Loops
Python Basics, Python Wallpaper, Python Code, Quantum Physics Science, Coding Websites, Technology Hacks, Computer Basic, Computer Knowledge, Computer Coding
Python Basics, Python Wallpaper, Python Code, Quantum Physics Science, Coding Websites, Technology Hacks, Computer Basic, Computer Knowledge, Computer Coding

While less common, you can install NetworkX directly from its source code. This method is useful if you want to contribute to NetworkX's development or require the latest features not yet released.

First, obtain the source code by cloning the NetworkX repository from GitHub:

git clone https://github.com/networkx/networkx.git

Then, navigate to the project directory and run pip to install NetworkX:

cd networkx python setup.py install

After a successful installation, you can import and use NetworkX as described earlier.

Congratulations! You have successfully installed NetworkX on your system. Now you're ready to create, manipulate, and study graphs using a versatile and efficient library. Start exploring the endless possibilities NetworkX offers and expand your data science skill set.