2
votes

I installed the python igraph library for anaconda following the directions in this thread installing python igraph, So the C core library and the python package were successfully installed. However, when I tried to import the igraph library in python, I am getting the following error

>>> import igraph
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/user/anaconda/lib/python2.7/site-packages/igraph/__init__.py", line 34, in <module>
    from igraph._igraph import *
ImportError: dlopen(/Users/user/anaconda/lib/python2.7/site-packages/igraph/_igraph.so, 2): Library not loaded: libxml2.2.dylib
  Referenced from: /Users/user/anaconda/lib/python2.7/site-packages/igraph/_igraph.so
  Reason: Incompatible library version: _igraph.so requires version 12.0.0 or later, but libxml2.2.dylib provides version 10.0.0

Looking for similar threads, I found a similar issue here Installation of python igraph with lxml problem. However, there is not a clear way on how to solve this issue. Does anyone know how to fix it? Thanks in advance.

2
See point 1) in my answer to another (but related) question here: stackoverflow.com/a/26994150/156771Tamás
Hi @Tamás. I found all the occurrences of libxml2*.dylib and they are in usr/local/Cellar/libxml2/2.9.2/lib/, usr/lib/, anaconda/lib, opt/local/lib and anaconda/pkgs/libxml2-2.9.0-1/lib which have 12.2.0 10.9.0, 12.2.0, 12.2.0 and 12.0.0 version respectively. Based on the suggestion on your previous thread , should I changed the name of the file in usr/lib/ which is the one that has the 10.9.0 version and leave the others as they are? Thank you.Paul
No, exactly the opposite - try to get rid of those that have version 12.x, recompile and then rename them back. The reason is that the linker obviously finds the one with version 10.9.0 when you try to import igraph, so if you renamed the one with version 10.9.0, then recompiled igraph, it would still be compiled with 12.0.0. (Also, libxml2 with ABI version 10.9.0 seems to be the system-wide libxml2, so renaming it is dangerous anyway).Tamás
Hi @Tamás. I tried what you said before but it still complain about import igraph, it says Reason: Incompatible library version: _igraph.so requires version 12.0.0 or later, but libxml2.2.dylib provides version 10.0.0. I was wondering if it is related with the places at which installation is performed. I am using brew to compile and install the core brew install igraph and then pip install python-igraph. But it seem to be that the core is in /usr/local/Cellar/igraph/0.7.1 and the python package in /Users/user/anaconda/lib/python2.7/site-packages/igraph/ Any suggestion?Paul
I have added a proper answer below - let's continue the discussion there.Tamás

2 Answers

1
votes

Anaconda Python is weird - it ships with its own version of libxml2 and when you run pip install python-igraph, igraph is probably linked against it. However, when you try to import igraph, the linker finds the system-wide libxml2, which has a lower ABI version, so that's why you see the error message.

The workaround for this is to ensure that during the compilation stage, Anaconda Python's libxml2 is not picked up by the compiler. setup.py in the Python interface of igraph actually contains this workaround - it tries to detect when you are compiling igraph against Anaconda Python on OS X and then it tweaks the environment a bit to ensure that the linker picks up the right version of libxml2. However, this workaround is enabled only if you do not have the C core of igraph installed on your machine - the installer will download the C core, tweak the environment to work around Anaconda Python, then compile the C core and the Python interface together in one single step.

So, the solution is probably one of the following:

  1. Move Anaconda Python's libxml2 out of the way (or maybe rename xml2-config from Anaconda Python's distribution temporarily), then compile and install the C core from Homebrew. (Use brew unlink igraph, brew uninstall igraph, brew install igraph to be on the safe side). Then you can run pip install python-igraph.

  2. Remove Homebrew's igraph entirely and just run pip install python-igraph - it will download the C core, perform the necessary tweaks and then compile everything.

1
votes

I had exactly the same issue and installing/force linking libxml2 worked for me:

brew install libxml2
brew link --force libxml2

Others also report the same solution and it appears to be working.