How to handle jupyter notebook files in Ubuntu?

Recently the project jupyter added the mime-type to the ipynb files: application/x-ipynb+json, and I'd like to launch easily these files without having to allways launch the terminal command:

cd /path/to/notebook
jupyter notebook

So I've adapted this blog post in order to:

  • launch a jupyter-notebook server when double clicking a ipynb file
  • add icon to ipynb files.
  • create a desktop Launcher to easily launch a jupyter notebook from a default folder or dragging and dropping a file or folder.

Here's how it looks, and see my answer below to understand how to do this.

enter image description here

2 Answers

1. Create a ipynb.xml mime-info file

<mime-info xmlns=' <mime-type type="application/x-ipynb+json"> <comment>IPython Notebook</comment> <glob pattern="*.ipynb"/> </mime-type>
</mime-info>

Then store the file in ~/.local/share/mime and update the mime database.

cp ipynb.xml ~/.local/share/mime
update-mime-database ~/.local/share/mime

2. Create a jupyter.desktop file

Caution: Edit paths to adapt it to your system and habits.

[Desktop Entry]
Version=1.0
Type=Application
Name=Jupyter
Icon="$HOME/.icons/jupyter-sq-text.svg"
Exec=/path/to/jupyter notebook %F
Path="$HOME/Documents/Notebooks"
Comment=Jupyter notebook
MimeType=application/x-ipynb+json;
Categories=Science;
Terminal=true

Then install the desktop file:

desktop-file-install --dir="$HOME/.local/share/applications" jupyter.desktop

3. Add the jupyter icon

I chose the svg version from the design repository of jupyter, and installed in ~/.local/share/icons

wget -o $HOME/.local/share/icons/jupyter-sq-text.svg

Finally, link the mime-type icon to the system:

sudo ln -s $HOME/.local/share/icons/jupyter-sq-text.svg /usr/share/icons/gnome/scalable/mimetypes/application-x-ipynb+json.svg
sudo gtk-update-icon-cache /usr/share/icons/gnome/ -f

Hope that's help!

For running Jupyter notebooks, you may prefer the above method.

Whereas for previewing a notebook, I recommend you take a look at nb-viewer. With it you can preview a Jupyter Notebook with a double click.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like