在 Python 3.7 上使用 igraph 绘制图形时出现问题

problems plotting graphs with igraph on Python 3.7

我正面临上述问题。我看到其他与我类似的问题,但没有答案解决我的问题。

我正在 Windowd 10 x64 上工作:C:/Users/Marco/PycharmProjects/ortuproject/Teoria Dei Grafi_script con NetworkX.py" ;

在 Pycharm 社区版我的终端下方。

(venv) C:\Users\Marco\PycharmProjects\ortuproject>pip install python_igraph-0.8.0-cp37-cp37m-win_amd64.whl
Requirement already satisfied: python-igraph==0.8.0 from file:///C:/Users/Marco/PycharmProjects/ortuproject/python_igraph-0.8.0-cp37-cp37m-win_amd64.whl in c:\users\marco\pycharmprojects\or
tuproject\venv\lib\site-packages (0.8.0)
Requirement already satisfied: texttable>=1.6.2 in c:\users\marco\pycharmprojects\ortuproject\venv\lib\site-packages (from python-igraph==0.8.0) (1.6.2)

(venv) C:\Users\Marco\PycharmProjects\ortuproject>pip install cffi
Collecting cffi
  Using cached cffi-1.14.0-cp37-cp37m-win_amd64.whl (176 kB)
Requirement already satisfied: pycparser in c:\users\marco\pycharmprojects\ortuproject\venv\lib\site-packages (from cffi) (2.20)
Installing collected packages: cffi
Successfully installed cffi-1.14.0

(venv) C:\Users\Marco\PycharmProjects\ortuproject>pip install cairocffi
Collecting cairocffi
  Using cached cairocffi-1.1.0.tar.gz (68 kB)
Requirement already satisfied: cffi>=1.1.0 in c:\users\marco\pycharmprojects\ortuproject\venv\lib\site-packages (from cairocffi) (1.14.0)
Requirement already satisfied: setuptools>=39.2.0 in c:\users\marco\pycharmprojects\ortuproject\venv\lib\site-packages (from cairocffi) (46.1.1)
Requirement already satisfied: pycparser in c:\users\marco\pycharmprojects\ortuproject\venv\lib\site-packages (from cffi>=1.1.0->cairocffi) (2.20)
Installing collected packages: cairocffi
    Running setup.py install for cairocffi ... done
Successfully installed cairocffi-1.1.0

现在:当我运行这个代码

import igraph as ig

g = ig.Graph()
g.vs["name"] = ["Alice", "Bob", "Claire", "Dennis", "Esther", "Frank", "George"]
g.vs["age"] = [25, 31, 18, 47, 22, 23, 50]
g.vs["gender"] = ["f", "m", "f", "m", "f", "m", "m"]
g.es["is_formal"] = [False, False, True, True, True, False, True, False, False]
layout = 'random'
ig.plot(g, layout = layout)

这是结果

C:\Users\Marco\PycharmProjects\ortuproject\venv\Scripts\python.exe "C:/Users/Marco/PycharmProjects/ortuproject/Teoria Dei Grafi_script con NetworkX.py"
Traceback (most recent call last):
  File "C:/Users/Marco/PycharmProjects/ortuproject/Teoria Dei Grafi_script con NetworkX.py", line 3, in <module>
    import igraph as ig
  File "C:\Users\Marco\PycharmProjects\ortuproject\venv\lib\site-packages\igraph\__init__.py", line 35, in <module>
    from igraph.clustering import *
  File "C:\Users\Marco\PycharmProjects\ortuproject\venv\lib\site-packages\igraph\clustering.py", line 36, in <module>
    from igraph.drawing.colors import ClusterColoringPalette
  File "C:\Users\Marco\PycharmProjects\ortuproject\venv\lib\site-packages\igraph\drawing\__init__.py", line 30, in <module>
    from igraph.drawing.graph import DefaultGraphDrawer
  File "C:\Users\Marco\PycharmProjects\ortuproject\venv\lib\site-packages\igraph\drawing\graph.py", line 27, in <module>
    from igraph.drawing.edge import ArrowEdgeDrawer
  File "C:\Users\Marco\PycharmProjects\ortuproject\venv\lib\site-packages\igraph\drawing\edge.py", line 17, in <module>
    cairo = find_cairo()
  File "C:\Users\Marco\PycharmProjects\ortuproject\venv\lib\site-packages\igraph\drawing\utils.py", line 413, in find_cairo
    module = __import__(module_name)
  File "C:\Users\Marco\PycharmProjects\ortuproject\venv\lib\site-packages\cairocffi\__init__.py", line 50, in <module>
    ('libcairo.so', 'libcairo.2.dylib', 'libcairo-2.dll'))
  File "C:\Users\Marco\PycharmProjects\ortuproject\venv\lib\site-packages\cairocffi\__init__.py", line 45, in dlopen
    raise OSError(error_message)  # pragma: no cover
OSError: no library called "cairo" was found
no library called "libcairo-2" was found
cannot load library 'libcairo.so': error 0x7e
cannot load library 'libcairo.2.dylib': error 0x7e
cannot load library 'libcairo-2.dll': error 0x7e

Process finished with exit code 1

我已经一一搜索了所有这些问题,但所有解决方案都是关于安装 GTK、pycairo 的,但它们不起作用。

有什么想法吗?谢谢!

问题是cairo C库本身还没有,请按照Anaconda中的instructions for installing it. It is actually easier to install python-igraph自动安装pycairo,包括必要的cairo C 库。

请注意,最近还专门为 igraph 打开了一个支持论坛:https://igraph.discourse.group/