networkx plot random graph Error

u2107 phani.lav at
Tue Jul 15 12:11:11 CEST 2014

I am trying to read a file with 3 columns with col 1 and 2 as nodes/edges and column 3 as weight (value with decimal)

I am trying to execute this code 

import networkx as nx

G = nx.read_edgelist('file.txt', data=[("weight")])

edge_labels = dict(((u, v), d["weight"]) for u, v, d in G.edges(data=True))
pos = nx.random_layout(G)
nx.draw(G, pos)
nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels)

import matplotlib.pyplot as plt;


File "", line 4, in <module>
    G = nx.read_edgelist('File.txt', data=[("weight")])
  File "<string>", line 2, in read_edgelist
  File "/usr/local/lib/python2.7/dist-packages/networkx-1.7-py2.7.egg/networkx/utils/", line 241, in _open_file
    fobj = _dispatch_dict[ext](path, mode=mode)
IOError: [Errno 2] No such file or directory: 'contactUSC_nodes_diff_small.txt'
lavanya at peerformance:~/Desktop/INRIA_Papers/Python$ python
Traceback (most recent call last):
  File "", line 4, in <module>
    G = nx.read_edgelist('contactUSC_node_diff_small.txt', data=[("weight")])
  File "<string>", line 2, in read_edgelist
  File "/usr/local/lib/python2.7/dist-packages/networkx-1.7-py2.7.egg/networkx/utils/", line 263, in _open_file
    result = func(*new_args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/networkx-1.7-py2.7.egg/networkx/readwrite/", line 367, in read_edgelist
  File "/usr/local/lib/python2.7/dist-packages/networkx-1.7-py2.7.egg/networkx/readwrite/", line 286, in parse_edgelist
    for (edge_key,edge_type),edge_value in zip(data,d):

ValueError: too many values to unpack

More information about the Python-list mailing list