Search code examples
pythonigraphcairopycairo

OSError importing python-igraph


I am trying to import igraph but it keeps throwing this error at me:

>>> import igraph

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/igraph/__init__.py", 
line 36, in <module>
    from igraph.clustering import *
  File "/usr/local/lib/python3.6/site-packages/igraph/clustering.py", 
line 36, in <module>
    from igraph.drawing.colors import ClusterColoringPalette
  File "/usr/local/lib/python3.6/site-
packages/igraph/drawing/__init__.py", line 27, in <module>
    from igraph.drawing.graph import DefaultGraphDrawer
  File "/usr/local/lib/python3.6/site-
packages/igraph/drawing/graph.py", line 27, in <module>
    from igraph.drawing.edge import ArrowEdgeDrawer
  File "/usr/local/lib/python3.6/site-packages/igraph/drawing/edge.py", 
line 17, in <module>
    cairo = find_cairo()
  File "/usr/local/lib/python3.6/site-
packages/igraph/drawing/utils.py", line 413, in find_cairo
    module = __import__(module_name)
  File "/usr/local/lib/python3.6/site-packages/cairocffi/__init__.py", 
line 41, in <module>
    cairo = dlopen(ffi, 'cairo', 'cairo-2')
  File "/usr/local/lib/python3.6/site-packages/cairocffi/__init__.py", 
 line 38, in dlopen
    raise OSError("dlopen() failed to load a library: %s" % ' / 
'.join(names))
OSError: dlopen() failed to load a library: cairo / cairo-2
  1. I have tried to follow this guide to install cairo but it throws this error and doesn't solve the igraph import issue: error: mandatory image surface backend feature could not be enabled

  2. I have also tried to install pycairo but that resulted in no module founds: cairo, which brought me back to square one.

  3. I tried running sudo port install cairo as per https://cairographics.org/download/ instructions. But that results in Error: Port cairo not found


My sys config:

  • MacOS High Sierra 10.13.1
  • Python 3.6
  • python-igraph 0.7.1

I am clueless as to what can be the issue. Any help would be highly appreciated. Thank you :)


Solution

  • Thanks to @Aiven I have managed to solve my issue. If anyone ever comes across the same problem, this have done the trick for me:

    brew install cairo
    brew install py2cairo
    brew install igraph  (install C-core)
    sudo pip install python-igraph (install igraph for python)