Can't install igraph with MacOS and pip3

Hi! I am trying to install igraph using pip. I’m currently getting this error message:

    Skipping optional fixer: buffer
    Skipping optional fixer: idioms
    Skipping optional fixer: set_literal
    Skipping optional fixer: ws_comma
    running build_ext
    Cannot find the C core of igraph on this system using pkg-config.
    We will now try to download and compile the C core from scratch.
    Version number of the C core: 0.7.1.post6
    We will also try: 0.7.1

    Version 0.7.1.post6 of the C core of igraph is not found among the nightly builds.
    Use the --c-core-version switch to try a different version.

    Could not download and compile the C core of igraph.

    Running setup.py install for python-igraph ... error
ERROR: Command errored out with exit status 1: /usr/local/bin/python3.6 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/yn/1q0c_j114s31jc1m39nrfplh0000gn/T/pip-install-83_rxu8b/python-igraph_bf9535e8b18a47388627b10fc6cbd6a7/setup.py'"'"'; __file__='"'"'/private/var/folders/yn/1q0c_j114s31jc1m39nrfplh0000gn/T/pip-install-83_rxu8b/python-igraph_bf9535e8b18a47388627b10fc6cbd6a7/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/yn/1q0c_j114s31jc1m39nrfplh0000gn/T/pip-record-lj8lul4q/install-record.txt --single-version-externally-managed --compile --install-headers /Library/Frameworks/Python.framework/Versions/3.6/include/python3.6m/python-igraph Check the logs for full command output.

So it looks like I need to install the C core. I have tried doing this with brew and it succeeded. I have also tried updating pip, installing libtool using brew, using different versions of Python (3.6 and 3.9), and I am not using Anaconda on this machine. Does anyone have any suggestions on getting this to work?

Hi there!
I’m not using Anaconda on my machine & would prefer to just use pip if possible.
I tried pinning the version to 0.7.1 because another user on Github was able to install it after downloading the C core. It is also ineffective for version 0.7.4, which appears to be the current version according to pip.
Right now I’m using python3.6 -m pip install igraph-python,which isn’t effective.
which pip returns /usr/local/bin/pip
which python returns /usr/local/bin/python3.6

I have an Intel Mac, from 2018.
Thank you!
Best,
Alyssa

(pronouns: she/her/hers)

Hi Alyssa!

TL;DR: use pip install python-igraph, not pip install igraph-python. :slight_smile:

The rest of this post is about other stuff that you should know about how the Python interface is distributed on PyPI.

So, first of all, the Python interface of igraph has pre-compiled Python wheels for pretty much every combination of OS/architecture that we support so there should be no need to compile it on macOS. Currently the Apple Silicon (i.e. the shiny new Apple M1 Mac) wheels are broken; I already fixed them but they will come with the next patch release only.

The next weird thing that I find in your pip output is that python-igraph is currently based on version 0.9.4 of the C core, not 0.7.1.post6 – that was ages ago, during the time when no one was working on igraph’s development (before the first CZI grant).

Third, I remembered that we no longer need to download the C core of igraph during the installation process because a matching version of the C core is now included in the PyPI source distribution (back in the past, there were too many problems about people not being able to download the C core, accidentally downloading the wrong version, or already having a wrong version of the C core on their machines when running pip install).

Then I realized that you are using pip install igraph-python, which is not the correct command line. You need to use pip install python-igraph. This is because of historical reasons. 15 years ago, when I was a much more inexperienced developer than what I am now, I registered python-igraph on PyPI instead of plain igraph because for some reason I thought that the name of the package on PyPI must match the name of the corresponding package in Debian Linux, and python-igraph was already in Debian at that time. igraph went unclaimed, and later on someone else registered it for an unrelated project. Then igraph's development stalled, someone got fed up with it, and forked the Python interface on PyPI with a few enhancements under igraph-python, which you tried to install now. Then the CZI grant came, igraph’s development gained momentum again, and there was no need any more for the igraph-python fork. igraph-python is now unmaintained and we were not able to contact the authors to sort out the situation (we never received any response from them).

However, we managed to contact the author of igraph, who was very receptive to the idea of handing over the igraph name to us, so right now igraph is under our control and the plan is to eventually transition python-igraph to igraph so people can use pip install igraph, as it would have been logical from the very first moment.

Bottom line: use pip install python--igraph and it should just work on most platforms. If it doesn’t, that’s a bug, and we need to fix it, but in this case we really need to figure out how you end up with a version of python-igraph that still looks for version 0.7.1.post6 of the C core. It looks like somehow you ended up with the wrong version of python-igraph. The correct version, which is written in src/igraph/version.py of the source tarball, is 0.9.6 at the moment.

One more thing that can potentially cause confusion: there is Python 2.x and Python 3.x. macOS ships an old version of Python 2.7 for compatibility reasons, so if you type python on a stock macOS installation, you end up with an outdated Python. Similarly, if you type pip on a stock macOS machine, you might end up with a version that interacts with this outdated Python. pip install python-igraph could then fail because it looks for the latest python-igraph version that supports Python 2.7, which is probably 0.7.1 or something like that. We dropped support for Python 2 a long time ago.

Now, if you want to make sure you are using Python 3, you can use python3 to launch the interpreter and pip3 to launch the version of pip that interacts with Python 3. So, if pip install python-igraph fails, try pip3 install python-igraph to make sure you are working with Python 3.

My preferred way to clear up this confusion with Python versions on macOS is to install Python 3 from Homebrew (i.e. brew install python3) and training myself to use python3 in the command line if I need to. Typically, in each of the projects I work, I create a Python virtual environment inside the project folder (with python3 -m venv .venv) and then in the context of a project I always use the virtual Python environment so I can safely install and uninstall dependencies without messing up my system Python. My system-based Python is basically used for spawning virtualenvs only.

Sorry about that, I misread your original message as “I am using Anaconda”. This is why I deleted my answer later.

Hi Tamas!
I successfully installed it with pip install python-igraph. I now appear to have version 0.9.6. Thank you so much!

Best,
Alyssa

(pronouns: she/her/hers)

1 Like