简体   繁体   中英

Problems Installing Python igraph on Mountain Lion OS X

I've installed the igraph C library using Brew,

sudo brew install igraph

I have then installed the igraph python library using pip

sudo pip install python-igraph

I go on the Python console/terminal and import the module

>>> 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 graph.

>>> g = Graph(1)

All i get is

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'Graph' is not defined

I've tried to re install everything, and it just keeps doing the same thing. Ran out of ideas now.

I don't think I'm doing anything funny, just following the instructions from Python tutorial page .

The answer is written on the tutorial page right before the "Creating a graph from scratch" section:

From now on, every example in the documentation will assume that igraph's objects and methods are imported into the main namespace (ie, we used from igraph import * instead of import igraph ). If you let igraph take its own namespace, please adjust all the examples accordingly.

So the bottom line is:

  1. If you used import igraph , use igraph.Graph(1) because the Graph constructor then resides in the igraph namespace.

  2. If you used from igraph import * , use Graph(1) because everything in the igraph module was imported into the main namespace.

I used

 from igraph import *

and that seemed to work.

Also, starting igraph through the terminal directly with

$ igraph

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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