2

I installed networkx module for python in windows and tried running a simple program on it using vs code. But when tried to run it says "AttributeError: module 'networkx' has no attribute 'Graph'". Not just Graph, if I use other networkx function it still says that networkx doesn't have that particular attribute. I face this problem in vs code only because when running it on IDLE it works fine. Please help

Here is my code:

import networkx as nx
import matplotlib.pyplot as p

G = nx.Graph()
G = nx.complete_graph(10)
nx.draw(G)
p.show()

Output:

 Traceback (most recent call last):
 File "c:/Python programs/networkx.py", line 1, in <module>
    import networkx as nx
  File "c:\Python programs\networkx.py", line 4, in <module>
    G = nx.Graph()
 AttributeError: module 'networkx' has no attribute 'Graph'
Firewreath
  • 21
  • 1
  • 2

1 Answers1

2

You can't name your file same as a module. Change the name of your file from networkx to something else.

Amartya
  • 35
  • 6