how to compute 'nearby' nodes with networkx

Use single_source_shortest_path or single_source_shortest_path_length with a cutoff of p

Something like:

nx.single_source_shortest_path_length(G ,source=i, cutoff=p)

Two years late, but I was looking for this same thing and found a built-in that I think will get the subgraph you want: ego_graph. The function signature and documentation:

ego_graph(G, n, radius=1, center=True, undirected=False, distance=None)

Returns induced subgraph of neighbors centered at node n within a given radius.