3

The code is written by someone else using Python 2.7.12, networkx 1.11, numpy 1.13.0, scipy 0.18.1, matplotlib 2.0.2. It consists of several self-made modules. I have converted the entire code to Python 3.x using "2to3" converter. I am running the entire code using Spyder which has all the latest packages.

Now while running the code I am getting AttributeError: 'DiGraph' object has no attribute '_node' error. Following is the error message in spyder.

runfile('C:/Users/NaVnEeT/Desktop/Thesis/WIP2/main.py', wdir='C:/Users/NaVnEeT/Desktop/Thesis/WIP2')
__main__    : INFO     main() started
Settings    : INFO     Settings __init__ finished
Settings    : INFO     Settings __init__ finished
Settings    : INFO     Settings __init__ finished
Settings    : INFO     Settings __init__ finished
Settings    : INFO     Settings __init__ finished
Settings    : INFO     Settings __init__ finished
Settings    : INFO     Settings __init__ finished
Settings    : INFO     Settings __init__ finished
Settings    : INFO     Settings __init__ finished
Settings    : INFO     Settings __init__ finished
TransGrph   : INFO     Graph is loaded from file
Traceback (most recent call last):

  File "<ipython-input-1-c61da2f96623>", line 1, in <module>
    runfile('C:/Users/NaVnEeT/Desktop/Thesis/WIP2/main.py', wdir='C:/Users/NaVnEeT/Desktop/Thesis/WIP2')

  File "C:\Users\NaVnEeT\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 710, in runfile
    execfile(filename, namespace)

  File "C:\Users\NaVnEeT\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 101, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/NaVnEeT/Desktop/Thesis/WIP2/main.py", line 137, in <module>
    main()

  File "C:/Users/NaVnEeT/Desktop/Thesis/WIP2/main.py", line 92, in main
    ch8NLR()

  File "C:\Users\NaVnEeT\Desktop\Thesis\WIP2\code\thesis\ch8NLR.py", line 176, in ch8NLR
    graph = TransportGraph(settings[0])

  File "C:\Users\NaVnEeT\Desktop\Thesis\WIP2\code\buildgraph\transportgraph.py", line 58, in __init__
    self.dmatrix = add_dmatrix(self.G, settings)

  File "C:\Users\NaVnEeT\Desktop\Thesis\WIP2\code\buildgraph\demandmatrix.py", line 20, in add_dmatrix
    origdest_graph = [x for x in G.nodes() if x[0] == 'F']

  File "C:\Users\NaVnEeT\Anaconda3\lib\site-packages\networkx\classes\graph.py", line 717, in nodes
    nodes = NodeView(self)

  File "C:\Users\NaVnEeT\Anaconda3\lib\site-packages\networkx\classes\reportviews.py", line 168, in __init__
    self._nodes = graph._node

AttributeError: 'DiGraph' object has no attribute '_node'

I can provide the part of the code if required for a solution.

Note: the code is running successfully with the old packages.

Norrius
  • 7,558
  • 5
  • 40
  • 49
kumar navneet
  • 31
  • 1
  • 1
  • 7

1 Answers1

4

If it runs in the old version, but not now, this error is probably caused by the old code being incompatible with networkx 2.x. You should read the migration guide for updating 1.x code to run in networkx 2.0.

edit: from comments, it's now clear that the problem was that the graph was created in 1.x and then pickled. So it has the 1.x attributes. But now it's being used with 2.x code which expects 2.x attributes. The solution is explained here.

Joel
  • 22,598
  • 6
  • 69
  • 93
  • Thank you for your reply. You are correct it the issue of networkx version. I have re-confirmed it by downgrading the networkx library but keeping the rest of the code in the 3.x version. This networkx part of the code is distributed in a lot of functions and libraries, I will try to put in a single file then post it here. If possible could you please give me a rough idea of this error 'AttributeError: 'DiGraph' object has no attribute '_node''. – kumar navneet Feb 08 '18 at 09:38
  • Can you tell me how you go about defining the graph (is it perhaps being loaded from an existing pickled object or something)? The error is occurring in a line of networkx's code which references `graph._node`. But DiGraphs (at least in networkx 2.x) have that attribute. So the only thing I can think of is that the DiGraph was created in 1.x, so it only has the 1.x attributes, but then it's being treated as a 2.x DiGraph. – Joel Feb 08 '18 at 20:10
  • Sorry for delayed response. Yes, you are right it was created using 1.x and the code uses existing pickle file to process further. I created the graph using 2.x and now it is working fine. – kumar navneet Feb 21 '18 at 15:32