Error occurred when running the code of GCN from the tutorial

I am a beginner to pytorch and DGL, and can anybody give any comments about the problem?

The code is downloaded from the tutorial website: https://docs.dgl.ai/tutorials/models/1_gnn/1_gcn.html


Traceback (most recent call last):
File “/home/hzhaoaf/anaconda2/envs/py35/lib/python3.5/site-packages/dgl/graph_index.py”, line 922, in create_graph_index
gi.from_networkx(graph_data)
File “/home/hzhaoaf/anaconda2/envs/py35/lib/python3.5/site-packages/dgl/graph_index.py”, line 660, in from_networkx
for e in nx_graph.edges:
TypeError: ‘method’ object is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “1_gcn.py”, line 116, in
g, features, labels, mask = load_cora_data()
File “1_gcn.py”, line 108, in load_cora_data
g = DGLGraph(data.graph)
File “/home/hzhaoaf/anaconda2/envs/py35/lib/python3.5/site-packages/dgl/graph.py”, line 181, in init
self._graph = create_graph_index(graph_data, multigraph, readonly)
File “/home/hzhaoaf/anaconda2/envs/py35/lib/python3.5/site-packages/dgl/graph_index.py”, line 925, in create_graph_index
% type(graph_data))
dgl._ffi.base.DGLError: Error while creating graph from input of type “<class ‘networkx.classes.digraph.DiGraph’>”.

Hi,

Which version of networkx are you using?

You can get the version by this:

import networkx
print(networkx.__version__)

The version of NetworkX is 1.11

Python 3.5.3 |Anaconda custom (64-bit)| (default, Mar 6 2017, 11:58:13)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import networkx
>>> networkx.version
‘1.11’
>>>

It seems your networkx version is too old.
Update it by using

conda update networkx

or

pip install --upgrade networkx

And after this, the new version is expected to be 2.2.

The problem is fixed after updating the networkX. Thanks very much.

However, another problem occurred in weakref.py. Can you also give any suggestions?

Hi, there seems to be many related problems and solutions on the internet like this. See if some of the solutions people propose can solve your issue.

It seems a python bug. Upgrade python may fix this.

Thank you very much. I will check it.

Thank for your help very much. There are no problems when I run the gcn in the directory “examples/pytorch” in the project. I will fix it later.