# Python find shortest path

**URL:** <https://igraph.discourse.group/t/python-find-shortest-path/1268>\
**Category:** Usage\
**Tags:** Python\
**Created:** [23 June 2022 15:42 UTC](https://igraph.discourse.group/t/python-find-shortest-path/1268 "2022-06-23T15:42:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![doric35](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/doric35/32/792_2.png) [@doric35](https://igraph.discourse.group/u/doric35)\
**Post date:** [23 June 2022 15:42 UTC](https://igraph.discourse.group/t/python-find-shortest-path/1268/1 "2022-06-23T15:42:00Z")

</div>

Hi,  
I just installed the python-igraph latest version using pip.  
I am trying to compute the shortest path between two nodes.  
I am coding in vscode, is it normal that i dont get to see the shortest path methods that are documented, but i get to see a dijkstra shortest path method that is not documented?  
See the image bellow.

 ![Capture d’écran, le 2022-06-23 à 11.41.41](https://global.discourse-cdn.com/free1/uploads/igraph/original/1X/e1ff3370899198e83379111acfb6693023fcab13.png)

---

<div class="post-metadata">

**Author:** ![tamas](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/tamas/32/1261_2.png) [@tamas](https://igraph.discourse.group/u/tamas)\
**Post date:** [23 June 2022 16:09 UTC](https://igraph.discourse.group/t/python-find-shortest-path/1268/2 "2022-06-23T16:09:16Z")

</div>

Our package structure is a bit convoluted due to historical reasons plus the fact that we are mixing C with Python. For instance, `shortest_paths_dijkstra` is simply an alias to `shortest_paths`; this is what we have in the code:

```python
class Graph(GraphBase):
    [...]
    # Compatibility aliases
    shortest_paths_dijkstra = GraphBase.shortest_paths
    subgraph = GraphBase.induced_subgraph

```

What probably happens is that `GraphBase` is a class implemented purely in C, so VS Code cannot look at its source code and parse it without importing the `igraph` module - which it won’t do for efficiency and safety reasons. `Graph` itself derives from `GraphBase` and extends the class with a few Python-based methods, and you’ll be able to see the documentation for these methods only (because VS Code can parse them from the source code without having to import `igraph`). If you want the full docs, you’ll have to go to [python-igraph API reference](https://igraph.org/python/api/latest/) to parse the full API reference.

---

<div class="post-metadata">

**Author:** ![doric35](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/doric35/32/792_2.png) [@doric35](https://igraph.discourse.group/u/doric35)\
**Post date:** [24 June 2022 18:47 UTC](https://igraph.discourse.group/t/python-find-shortest-path/1268/4 "2022-06-24T18:47:34Z")

</div>

Also, there seems to be an issue with the way i use the shortest path method.

I created a weighted directed graph using TupleList, and i clearly added the edge (0,84) with weight 10001;  
 ![Capture d’écran, le 2022-06-24 à 14.39.23](https://global.discourse-cdn.com/free1/uploads/igraph/original/1X/cfd80f3af3693a9528212c6038de0dce0ade9017.png)

---

<div class="post-metadata">

**Author:** ![doric35](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/doric35/32/792_2.png) [@doric35](https://igraph.discourse.group/u/doric35)\
**Post date:** [24 June 2022 18:48 UTC](https://igraph.discourse.group/t/python-find-shortest-path/1268/5 "2022-06-24T18:48:15Z")

</div>

but when i compute the shortest path between the two vertex, i do not get that solution;  
 ![Capture d’écran, le 2022-06-24 à 14.44.40](https://global.discourse-cdn.com/free1/uploads/igraph/original/1X/6210032cdd15ecd488fe5ca006bef8a70f43ffa7.png)

With a weight of 70004

---

<div class="post-metadata">

**Author:** ![doric35](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/doric35/32/792_2.png) [@doric35](https://igraph.discourse.group/u/doric35)\
**Post date:** [24 June 2022 19:19 UTC](https://igraph.discourse.group/t/python-find-shortest-path/1268/6 "2022-06-24T19:19:35Z")

</div>

For the record, i do not get this issue as i initialize my graph with the usual Graph() constructor

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [25 June 2022 19:28 UTC](https://igraph.discourse.group/t/python-find-shortest-path/1268/7 "2022-06-25T19:28:02Z")

</div>

It’s unclear what your screenshot is meant to show. Can you give a minimal reproducible example, with _copyable_ code, according to the guidelines [here](https://stackoverflow.com/help/minimal-reproducible-example)?
