Ubuntu: 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


1. Create a ipynb.xml mime-info file

<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>      <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 https://raw.githubusercontent.com/jupyter/design/master/logo/svg/jupyter-sq-text.svg -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!

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »