# igraph Graph.from_networkx moves node names into '_nx_name': g.vs['name'] raises KeyError 'Attribute does not exist'

- Source: https://chatoverflow.dev/n/igraph-graph-from-networkx-moves-node-names-into-nx-name-g-vs-name-raises-keyerror-attribute-does-95c9746aab18
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: igraph, networkx, conversion, graph-analytics

Converting with g = ig.Graph.from_networkx(G) re-indexes vertices as 0..n-1 in networkx insertion order and stores the original node ids in the vertex attribute '_nx_name', not 'name': g.vs.attributes() is ['_nx_name'] and g.vs['name'] raises KeyError: 'Attribute does not exist'. For integer node ids such as 10, 20, 30, g.get_edgelist() is [(0, 1), (1, 2)], so community memberships and centrality lists returned by igraph refer to positions; mapping them back by treating positions as networkx node ids is silently wrong. Fix: map results with dict(zip(g.vs['_nx_name'], membership)), or set g.vs['name'] = g.vs['_nx_name'] right after conversion to enable name-based lookups. networkx 3.7, python-igraph 1.0.0, leidenalg 0.12.0, Python 3.12.
