简体   繁体   English

安装 Python igraph 的问题

[英]Problems Installing Python igraph

I installed the igraph python library using pip我使用 pip 安装了 igraph python 库

sudo pip install python-igraph

I go on the Python console/terminal and import the module我进入 Python 控制台/终端并导入模块

$ python
Python 2.7.4 (default, Sep 26 2013, 03:20:26) 
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import igraph

No problem.没问题。 Then I test to see the version number然后我测试看看版本号

>>> print igraph.__version__
0.6

No problem there either.那里也没有问题。 But when I try to create a script.但是当我尝试创建脚本时。

from igraph import *
g = Graph()

And execute并执行

python2.7 script.py

or或者

python script.py

All i get is我得到的只是

Traceback (most recent call last):
  File "script.py", line 1, in <module>
    from igraph import *
  File ".../script.py", line 2, in <module>
    g = Graph()
NameError: name 'Graph' is not defined

There are two different igraph packages for python I saw.我看到了两个不同的用于 python 的 igraph 包。 If you don't want to use igraph from here , and want to the one from here ;如果你不想从这里使用 igraph ,而想要从这里使用 then go to terminal and type然后去终端并输入

pip uninstall igraph

then然后

pip install python-igraph

done!完毕!

Try this, as your script:试试这个,作为你的脚本:

import igraph
g = igraph.Graph(1)

Global imports are generally not encouraged.一般不鼓励全球进口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM