Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Link to python file in Jupyter notebook markup cell

Suppose the following: I locally execute the jupyter-notebook server in my home directory.

I have the following files in ~/temp/jupyter_link:

index.ipynb  python_file.py

In a markup cell in index.ipynb I want to create a link to python_file.py. This link should open python_file.py with the jupyter-notebook editor. I can do that with:

[python_file](https://localhost:8888/edit/temp/jupyter_link/python_file.py)

However, this link contains the absolute path of python_file.py. I want to use the relative path (with the base directory being the one from index.ipynb). I can create a link using the relative path with:

[python_file](python_file.py)

However, if I click this link I'm asked to download the file and it's not opened with the jupyter-notebook editor.

Is it possible to create a link that opens the python file with the jupyter-notebook editor but that uses a relative path? The pseudo-code I imagine would be something like:

[python_file](edit:python_file.py)

Inspired by @Ivan's answer I might add that

[python_file](/edit/temp/jupyter_link/python_file.py)

also opens the editor. That removes the host name from the link, but still does not give me a relative link.

like image 372
Fabian Rost Avatar asked Oct 12 '16 12:10

Fabian Rost


People also ask

How do I embed code in markdown cell?

Press Esc key, type m for markdown cell, press Enter key. The cursor is now in the markdown cell waiting for instructions. Type your code or paste a code block. If code is pasted, it will most likely need to become aligned below the tickmarks.


1 Answers

The following seems to work (nowadays?) in Jupyter 5.4.1 and Jupyterlab 0.32.1:

[python_file](./python_file.py)
like image 149
Krachtwerk Avatar answered Oct 20 '22 00:10

Krachtwerk