3

I've installed py2cairo using brew, but keep getting errors when trying to plot with igraph. I get the following error:

>>> import igraph as ig
>>> from igraph import *
>>> UG = ig.Graph()
>>> UG.add_vertex('a')
>>> UG.add_vertex('b')
>>> UG.add_vertex('c')
>>> UG.add_vertex('d')
>>> UG.add_edge('a','d')
>>> UG.add_edge('a','c')
>>> UG.add_edge('b','c')
>>> UG.add_edge('b','a')

>>> layout = UG.layout_kamada_kawai()
>>> plot(UG,layout = layout)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../anaconda/lib/python2.7/site-packages/igraph/drawing/__init__.py", line 427, in plot
    result = Plot(target, bbox, background="white")
  File ".../anaconda/lib/python2.7/site-packages/igraph/drawing/__init__.py", line 122, in __init__
    self._surface_was_created = not isinstance(target, cairo.Surface)
  File ".../anaconda/lib/python2.7/site-packages/igraph/drawing/utils.py", line 396, in __getattr__
    raise TypeError("plotting not available")
TypeError: plotting not available

3 Answers3

2

brew probably installs py2cairo for its own Python, while you are running igraph under Anaconda Python. A module installed for one Python distribution on your machine will not appear magically under the other Python distribution, so you'll either have to get py2cairo for Anaconda Python or compile the Python interface of igraph for Homebrew's Python.

Tamás
  • 47,239
  • 12
  • 105
  • 124
  • Thanks for the help! I searched for py2cairo installation with Anaconda, and I got the following -- http://stackoverflow.com/questions/11491268/install-pycairo-in-virtualenv I tried installing cairo with ' pip install cairocffi' the installation had no errors, but I was unable to call 'import cairocffi' from python module Other option I found was to install cairo with brew -- is the only option to install 'py2cairo' uninstall Anaconda python and install python with brew? – curiousgeorgia Mar 21 '15 at 19:35
  • 2
    Probably the same issue; when you type `pip install cairocffi`, it installs `cairocffi` into one of your Python distributions, and then you try to import it from the other one. As for your last question: no, there are plenty of other ways; for instance, I compiled Python on my own using `pyenv` and then I compiled both `igraph` and `cairo` for this particular Python installation. You only have to make sure that when you invoke `pip install whatever`, then you call the "right" `pip`, i.e. the one that belongs to the Python distribution that you intend to use. – Tamás Mar 21 '15 at 21:05
  • So, if Anaconda Python provides its own copy of `pip`, make sure to call that particular `pip` when you invoke `pip install cairocffi` and not the one that comes with OS X by default. – Tamás Mar 21 '15 at 21:05
  • I will look into this and get back to you - thank you for the help! – curiousgeorgia Mar 24 '15 at 15:05
1

try updating your PYTHONPATH variable, e.g. (insert your username in place of NNNN):

export PYTHONPATH=/Users/NNNN/anaconda/bin/python:$PYTHONPATH
wlud
  • 11
  • 1
0

I had the same problem. I tried to install pycairo, py2cairo but igraph's plot would not work.

The following solved the igraph plotting issue:

sudo pip install cairocffi

Instead of pycairo I used cairocffi and this solved my problem.

seralouk
  • 30,938
  • 9
  • 118
  • 133