python - igraph plot not available (cairo already installed)

让人想犯罪 __ 提交于 2019-12-10 18:48:57

问题


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

回答1:


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.




回答2:


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

export PYTHONPATH=/Users/NNNN/anaconda/bin/python:$PYTHONPATH



回答3:


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.



来源:https://stackoverflow.com/questions/28970480/python-igraph-plot-not-available-cairo-already-installed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!