python - 在 Mountain Lion OS X 上安装 Python igraph 时出现问题

标签 python installation python-2.7 igraph

我已经使用 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 of import igraph). If you let igraph take its own namespace, please adjust all the examples accordingly.

所以底线是:

  1. 如果您使用 import igraph,请使用 igraph.Graph(1),因为 Graph 构造函数驻留在 >igraph 命名空间。

  2. 如果您使用 from igraph import *,请使用 Graph(1),因为 igraph 模块中的所有内容都已导入到主命名空间。

关于python - 在 Mountain Lion OS X 上安装 Python igraph 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12783492/

相关文章:

python - imshow() 子图生成不需要的空白

linux - 为什么我的自定义 Perl 不能安装到预期的目录中?

python-3.x - SKLearn 0.20.2 - RandomizedPCA 的导入错误?

python - 遍历字典值?

python - 变色龙中的断线

height - Inno Setup 设置 TInputQueryWizardPage 高度

python - .remove 不删除给定的字符串

python - 如何将 exe 转换回 Python 脚本

python - 在 Kali Linux 中,为什么我在/usr/bin/中只看到 python2 和 python3 二进制文件(不是 'python' 二进制文件)并得到 "python command not found"

python - 在进程之间共享不断发展的字典