AttributeError: module 'networkx' has no attribute 'Graph'
15,534
Following the below steps, it worked for me in python 3.5
version.
- Downloaded networkx-1.11.zip
- Extracted the zip file
- open the cmd and
cd to extracted directory
- run
python setup.py install
- verified the installation using
pip freeze
- saved the test code in
netExample.py
file. - In CMD, cd to the folder, which contains
netExample.py
- run
python netExample.py
Following is output that I got:
D:\Naveen\so>python netExample.py
[]
[]
<class 'list'>
<class 'list'>
Please check the following:
- Verify whether you are downloading from the official website.
- Check if any other file named
networkx.py
is present in Windows Path before the actualnetworkx
module is present in
Author by
NBC
Updated on July 16, 2022Comments
-
NBC almost 2 years
I installed networkx by downloading the distribution file and running:
python setup.py install
It appears to have been successful, I got this message after installing
Installed c:\python\python36-32\lib\site-packages\decorator-4.0.11-py3.6.egg Finished processing dependencies for networkx==1.11
But when I run a really simple test code, I get errors
import networkx as nx G=nx.Graph() print(G.nodes()) print(G.edges()) print(type(G.nodes())) print(type(G.edges()))
> Traceback (most recent call last): File "netExample.py", line 3, in > <module> > G=nx.Graph() > AttributeError: module 'networkx' has no attribute 'Graph'
Running
print(dr(nx))
gives the following attributes:> ['GraphMLReader', 'GraphMLWriter', '__builtins__', '__cached__', > '__doc__', '__file__', '__loader__', '__name__', '__package__', > '__path__', '__spec__', 'exception', 'generate_adjlist', > 'generate_edgelist', 'generate_gexf', 'generate_gml', > 'generate_graph6', 'generate_graphml', 'generate_multiline_adjlist', > 'generate_pajek', 'generate_sparse6', 'parse_adjlist', > 'parse_edgelist', 'parse_gml', 'parse_graph6', 'parse_graphml', > 'parse_leda', 'parse_multiline_adjlist', 'parse_pajek', > 'parse_sparse6', 'read_adjlist', 'read_edgelist', 'read_gexf', > 'read_gml', 'read_gpickle', 'read_graph6', 'read_graphml', > 'read_leda', 'read_multiline_adjlist', 'read_pajek', 'read_shp', > 'read_sparse6', 'read_weighted_edgelist', 'read_yaml', 'readwrite', > 'relabel_gexf_graph', 'utils', 'write_adjlist', 'write_edgelist', > 'write_gexf', 'write_gml', 'write_gpickle', 'write_graph6', > 'write_graphml', 'write_multiline_adjlist', 'write_pajek', > 'write_shp', 'write_sparse6', 'write_weighted_edgelist', 'write_yaml']