1

I have the a very simple script to get started with networkx python module, which looks as follows:

import networkx as nx

g = nx.Graph() 
g.add_edge('a','b',weight=0.1) 
g.add_edge('b','c',weight=1.5) 
g.add_edge('a','c',weight=1.0) 
g.add_edge('c','d',weight=2.2) 
print nx.shortest_path(g,'b','d')

When I run this using the command python filename.py, I get the following error:

Traceback (most recent call last):
  File "filename.py", line 1, in <module>
    import networkx as nx
  File "/home/path_to_file/filename.py", line 3, in <module>
AttributeError: 'module' object has no attribute 'Graph'

When I run the same lines of code, not as whole, but line by line in the command line, it works completely fine as seen the screen-shot below: enter image description here

What am I missing?

P.S: I am on Ubuntu 16.04 LTS using python version 2.7

kingmakerking
  • 2,017
  • 2
  • 28
  • 44

0 Answers0