6

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']
Red
  • 26,798
  • 7
  • 36
  • 58
NBC
  • 1,606
  • 4
  • 18
  • 31
  • 1
    check using `pip freeze` whether `networkx` module is successfully installed or not. restart cmd or terminal if required. what is the file name of your script? `networkx.py`? If yes, rename it to some other name, it will work. – Naveen Kumar R B Feb 07 '17 at 08:39
  • it appears it did, it gives me the text "networkx==1.11" the file name of my script is "netExamply.py" – NBC Feb 07 '17 at 08:43
  • 1
    the name of the script is all right (a classic, but not here): `netExample.py` in the stacktrace. Can you do: `print(dir(nx))` to see the available members/objects. – Jean-François Fabre Feb 07 '17 at 08:44
  • Graph isn't one of them (full response too long to post in comment). Does that mean a faulty install? – NBC Feb 07 '17 at 08:48

1 Answers1

2

Following the below steps, it worked for me in python 3.5 version.

  1. Downloaded networkx-1.11.zip
  2. Extracted the zip file
  3. open the cmd and cd to extracted directory
  4. run python setup.py install
  5. verified the installation using pip freeze
  6. saved the test code in netExample.py file.
  7. In CMD, cd to the folder, which contains netExample.py
  8. run python netExample.py

Following is output that I got:

D:\Naveen\so>python netExample.py
[]
[]
<class 'list'>
<class 'list'>

Please check the following:

  1. Verify whether you are downloading from the official website.
  2. Check if any other file named networkx.py is present in Windows Path before the actual networkx module is present in
Naveen Kumar R B
  • 6,248
  • 5
  • 32
  • 65
  • 1
    This is exactly what I did last time, but I think something must have gone wrong during the extraction part. Works like a charm now! – NBC Feb 08 '17 at 06:44