我已经使用 Brew 安装了 igraph C 库,
sudo brew install igraph
然后我使用 pip 安装了 igraph python 库
sudo pip install python-igraph
我进入 Python 控制台/终端并导入模块
>>> import igraph
没问题。然后我测试看看版本号
>>> print igraph.__version__
0.6
那里也没有问题。但是当我尝试创建图表时。
>>> g = Graph(1)
我得到的只是
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'Graph' is not defined
我尝试重新安装所有内容,但它只是继续做同样的事情。现在没有主意了。
我不认为我在做任何有趣的事情,只是按照 Python tutorial page 的指示进行操作.
最佳答案
答案写在tutorial page上就在“从头开始创建图表”部分之前:
From now on, every example in the documentation will assume that igraph‘s objects and methods are imported into the main namespace (i.e., we used
from igraph import *
instead ofimport igraph
). If you let igraph take its own namespace, please adjust all the examples accordingly.
所以底线是:
如果您使用
import igraph
,请使用igraph.Graph(1)
,因为Graph
构造函数驻留在>igraph
命名空间。如果您使用
from igraph import *
,请使用Graph(1)
,因为igraph
模块中的所有内容都已导入到主命名空间。
关于python - 在 Mountain Lion OS X 上安装 Python igraph 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12783492/