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

I try to use networkx to read in a gml file (quite simple?), Except whenever I try to read in a file, I get the error "networkx.exception.NetworkXError: cannot tokenize u'graph" at (3, 1) "I am not too familiar with gml or networkx, so I myself could not diagnose the problem.

What is even more strange, since my colleague will execute the same command with the same file, and it will execute without errors. I uninstalled and reinstalled networkx several times at this point, can anyone help to determine what the error might come from?

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

Traceback (last last call):

File, line 1, in

File "", line 2, in read_gml

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

File "/ usr / local / lib / python 2.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 / python 2.7 / dist-packages / networkx / readwrite / gml.py", line 383, in parse_gml_lines graph = parse_graph ()

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

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

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

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

+6
source share
3 answers

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

See this question .

+2
source

Yes. A good solution for switching to a network solution 1.9.1. 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 will automatically remove networkx 1.10 and replace it with networkx 1.9.1.

+1
source

I'm not sure about the format of your gml file, but reformatting your gml file may solve your problem.

Check out my answer to this post .

0
source

All Articles