Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)

like image 903
mgrogger Avatar asked Aug 11 '15 15:08

mgrogger


2 Answers

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

See this question.

like image 161
Hernandcb Avatar answered Nov 17 '22 17:11

Hernandcb


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.

like image 1
Ulinuha Avatar answered Nov 17 '22 17:11

Ulinuha