Networkx read_gml error “networkx.exception.Networ

2019-06-16 18:15发布

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)

3条回答
小情绪 Triste *
2楼-- · 2019-06-16 18:33

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

See this question.

查看更多
何必那么认真
3楼-- · 2019-06-16 18:42

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.

查看更多
啃猪蹄的小仙女
4楼-- · 2019-06-16 18:47

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.

查看更多
登录 后发表回答