在通过自制软件安装py2cairo
,cairo
和igraph
之后,我遇到了一个未导入cairo库的问题。
我试图在python3 shell中运行以下代码
>>> from igraph import *
>>> g = Graph.Famous("petersen")
>>> plot(g)
它给了我错误:TypeError:plotting not available
当我在shell中运行import cairo
时,它给了我:
>>> import cairo
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'cairo'
有关调试,请参阅我用来安装cairo,py2cairo和igraph的命令
brew install cairo, py2cairo
brew install homebrew/science/igraph
它们可通过以下途径获得: 的/ usr /本地/地窖/
当我查看我的python路径时,它是:
>>> import os
>>> os.path
<module 'posixpath' from '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/posixpath.py'>
以下路径py2cairo
无法提供cairo
和/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/
安装,但路径中不存在igraph
有人可以帮我解决这个问题吗?
=============================================== ============================ UPDATE:
我尝试通过(参考:Can't load Python modules installed via pip from site-packages directory)从python shell运行以下命令解决问题,这次我可以在python shell中导入cairo。
>>> import sys
>>> sys.path.append("/usr/local/Cellar")
>>> import cairo
但是,它在plot(g)
行上失败并出现以下错误。
>>> plot(g)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site- packages/igraph/drawing/__init__.py", line 446, in plot
result = Plot(target, bbox, background=kwds.get("background", "white"))
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site- packages/igraph/drawing/__init__.py", line 117, in __init__
self._surface_was_created = not isinstance(target, cairo.Surface)
AttributeError: module 'cairo' has no attribute 'Surface'
任何帮助将不胜感激