8
votes

I'm trying to use networkx to read in a gml file (pretty simple right?), except whenever I try to read in the file, I get the error "networkx.exception.NetworkXError: cannot tokenize u'graph' at (3, 1)" I'm not too familiar with gml or networkx, so I haven't been able to diagnose the problem myself.

What's even weirder is that my coworker will run the exact same command with the exact same file, and it will execute without error. I've uninstalled and reinstalled networkx several times at this point, can anyone help determine what the error could be coming from?

import networkx as nx
g = nx.read_gml('disciplineNetwork.gml')

Traceback (most recent call last):

File "", line 1, in

File "", line 2, in read_gml

File "/usr/local/lib/python2.7/dist-packages/networkx/utils/decorators.py", line 220, in _open_file result = func(*new_args, **kwargs)

File "/usr/local/lib/python2.7/dist-packages/networkx/readwrite/gml.py", line 210, in read_gml G = parse_gml_lines(filter_lines(path), label, destringizer)

File "/usr/local/lib/python2.7/dist-packages/networkx/readwrite/gml.py", line 383, in parse_gml_lines graph = parse_graph()

File "/usr/local/lib/python2.7/dist-packages/networkx/readwrite/gml.py", line 372, in parse_graph curr_token, dct = parse_kv(next(tokens))

File "/usr/local/lib/python2.7/dist-packages/networkx/readwrite/gml.py", line 347, in parse_kv curr_token = next(tokens)

File "/usr/local/lib/python2.7/dist-packages/networkx/readwrite/gml.py", line 323, in tokenize (line[pos:], lineno + 1, pos + 1))

networkx.exception.NetworkXError: cannot tokenize u'graph' at (3, 1)

4
Same operating system on your and your colleague's computer? - Joel
colleague also using python2.7? - Joel
Downgrade as mentioned below is correct. The new networkx can't handle the gml files generated by the old one :( - Ezekiel Kruglick
One quick note: watch out for the downgrade! You will need to do so to read this older form GML file. Sadly, 1.9.1 has it's own bugs in reading GMLs, detailed here: stackoverflow.com/questions/19352960/… - dpb

4 Answers

3
votes

I had the same problem and the solution for me was downgrading the version of networkx.

See this question.

1
votes

Yes. Downgrade to networkx 1.9.1 is a good solution. You can download networkx 1.9.1 at https://pypi.python.org/pypi/networkx/1.9.1. Download the zip file. Then use: pip install networkx-1.9.1.zip. This automatically uninstall networkx 1.10 and replace it with networkx 1.9.1.

0
votes

A bit of an old question but I had the same problem but found a different solution which doesn't require downgrading networkx (though does require another program).

If you use Gephi as a graph editor/drawing system (or any of the others I imagine) they include an export graph functionality which will let you export graph files in a wide range of other formats.

So I loaded the graph as .gml then exported as .graphml for which networkx has no problems to load and continue working on.

If it's any help.

-1
votes

I am not sure about the format of your gml file, but reformatting your gml file may solve your issue.

Check my answer on this post.