你寻找single_source_dijkstra https://networkx.github.io/documentation/stable/reference/algorithms/generated/networkx.algorithms.shortest_paths.weighted.single_source_dijkstra.html:
from networkx.algorithms.shortest_paths.weighted import single_source_dijkstra
single_source_dijkstra(G,s,t)
example
import networkx as nx
from networkx.algorithms.shortest_paths.weighted import single_source_dijkstra
G = nx.Graph()
G.add_edge('a', 'b', weight=0.6)
G.add_edge('a', 'c', weight=6)
G.add_edge('c', 'd', weight=0.1)
G.add_edge('c', 'e', weight=0.7)
G.add_edge('c', 'f', weight=0.9)
G.add_edge('a', 'd', weight=0.3)
single_source_dijkstra(G,'b','f')
output
(1.9, ['b', 'a', 'd', 'c', 'f'])