Install and start using python-igraph
igraph is on the Python
Package Index with pre-compiled wheels for most Python distributions
and platforms, so in most cases it can simply be installed using
The command above should attempt to download a pre-compiled wheel if
your platform and Python version are among the supported ones. Currently
we aim to support Windows, Linux and macOS for at least the three most
recent minor versions of Python 3.x. If you are still using Python 2.7,
python-igraph 0.8.x is the latest version that you should
attempt to install.
In cases where we don't provide a pre-compiled wheel, the command
above will attempt to compile the Python interface of igraph during
installation. See the next section about the requirements for compiling
python-igraph from source.
In general, you will need a working C and C++ compiler, a POSIX-compatible
shell environment (MSYS2 on Windows
make, and the development header files for your
version of Python. You will also need
for GraphML support.
libxml2 might have additional
dependencies depending on your platform; for instance, you also
zlib1g-dev on Linux; more about these in the
platform-specific instructions below.
The source code of the Python interface bundles a matching version of the C core of the igraph library, and this will be linked to the compiled Python interface statically during the build process, so if everything is installed properly, you can simply run the following command even if we provide no matching pre-compiled wheel:
However, if the C core of igraph has already been installed to a
location that can be discovered using
you can also instruct the setup script to use
instead of compiling the bundled version with
pip will compile and link the extension to the
C core that you have installed. First you need to download and extract
the source code of the Python interface:
Next, make sure that
pkg-config can correctly report
the compilation flags needed to link to
following command should list a bunch of compiler and linker flags
instead of reporting an error:
Finally, ask the setup script to compile
pkg-config for the detection of the C core:
See the sections below for additional, platform-specific instructions.
On Debian and Ubuntu Linux, installing
python3.X-dev for your
matching version of Python),
zlib1g-dev should be enough to get you started. The
latter two are needed only if you need GraphML support. Running
pip install --user python-igraph after having installed
all these dependencies should then work out-of-the-box.
If you are using some other Linux distribution, try to find the
packages equivalent to the ones mentioned above; in general, you will
need the usual development tools (at least a C and C++ compiler
make), the development headers for your Python
version, and the development headers for
libxml2 if you
need GraphML support. Feel free to send us a message in the
discussion forum if you
can provide more specific instructions for a popular Linux flavour
that we have not listed here.
On macOS, you can get a working C and C++ compiler as well as
make by installing XCode or the XCode Command Line Tools.
pip install python-igraph should then work
You can also install a pre-compiled version of the C core of igraph from
Homebrew. This can be used in conjunction
pkg-config as outlined in the section about
compiling from source to link the Python interface
to the C core installed from Homebrew.
Compilation on Windows is more complicated than on other platforms because the C core of igraph needs to be built in a POSIX shell-like environment at the moment, but the Python interface has to be compiled with Microsoft Visual C instead (like all other Python extensions). Ideally, you should be able to use one of the pre-compiled wheels, but in case you can't, here is a rough outline of how we managed to get it work in our continuous integration environment. As we do not use Windows regularly, these instructions might need small tweaks; any improvements are appreciated in our discussion forum.
First, you need to follow the instructions on the Python wiki to install the version of the Microsoft Visual C++ Compiler that matches your Python version.
Next, you also need to download MSYS2, which provides a shell environment in which the C core of igraph can be compiled.
Then you need to install a bunch of dependencies in MSYS2. Open up the MSYS2 shell and run the following command:
Then you need to download the source code of
from PyPI and extract it to a folder. Open the MSYS2 shell, enter this
folder and run
python setup.py build_c_core. This should
compile the C core of the Python interface with MSYS2.
You are not done yet, read on.
Once the C core is compiled, you need to switch back to the "regular"
WIndows shell, make sure that the Visual C compiler is on your PATH
(typically there are scripts in the Visual Studio installation that
let you launch a development shell with MSVC on your PATH), and then
python setup.py build, followed by
python setup.py install.
Note that the instructions above work in our CI environment, but your environment might be different from ours so these instructions might require small tweaks. Improvements are welcome; please open a thread in our discussion forum if you can add more specific instructions.
Documentation for the Python interface is also included in
the Python docstrings, so you can use
the built-in Python help facility as well.
Clone (or fork) the
master branch from the
repository on GitHub.
Post your question on the igraph support forum . Make sure that you include a minimal reproducible example, complete with code and data.
Post specific igraph questions on
Stack Overflow. Make sure that you include the
igraph tag and that you include a reproducible
example, complete with code and data.
Report bugs or suggest new features or algorithms in the GitHub issue tracker.
Your contribution is more than welcome!
Send a pull request on GitHub. Please note that igraph can contain only code that is compatible with its GPL license.