41

Related posts: Open an ipython notebook via double-click on osx

How can I open Ipython notebook from double click? I always cd to the directory of the notebook, then type ipython notebook in the browser and then open it in the browser. This steps is very inconvenient.

In windows, I remembered that I can change the directory in the browser, but in linux there is no way to explore to other directory via browser, if I want to open a new book in another directory, I have to restart another kernel as above, which annoys me.

Is there any simple and verified way to do this?

11
  • "Double click" - are you using some GUI for your Linux?
    – Jongware
    Commented Jun 20, 2015 at 11:31
  • 2
    @Jongware, looks like there are some people out there now who prefer desktop environments over the pure command line interface. Really weird.
    – cel
    Commented Jun 20, 2015 at 11:41
  • 1
    The question you linked has a solution for ubuntu. Is this solution not working for you?
    – cel
    Commented Jun 20, 2015 at 11:44
  • @Jongware Are you using no GUI ? I'm using one Commented Jun 20, 2015 at 11:46
  • 2
    @cel Everyone can't be geek (yet) and command lines may be a very freaking thing for many people. Nevertheless, python's notebook is a great tool to learn using python (which itself maybe a first step to be geek...). In that perspective, an easy opening mechanism for .ipynb files is essential to allow python's notebook to be used by a large audience.
    – jvtrudel
    Commented Aug 12, 2015 at 14:52

5 Answers 5

28

You can use a project like nbopen that handle that and will open the browser on the right notebook + start an IPython server if one is not yet running.

9
  • Traceback (most recent call last): File "/usr/local/bin/nbopen", line 3, in <module> main() File "/usr/local/lib/python2.7/dist-packages/nbopen.py", line 49, in main nbopen(args.filename, args.profile) File "/usr/local/lib/python2.7/dist-packages/nbopen.py", line 26, in nbopen server_inf = find_best_server(filename, profile) File "/usr/local/lib/python2.7/dist-packages/nbopen.py", line 14, in find_best_server servers = [si for si in notebookapp.list_running_servers(profile=profile) \ AttributeError: 'module' object has no attribute 'list_running_servers' Commented Jun 20, 2015 at 15:48
  • error occurs, also no response of double click. Although the file icon changes to ipynb Commented Jun 20, 2015 at 15:49
  • @buzhidao what version of IPython are you using? You may need to upgrade it for nbopen to work.
    – Thomas K
    Commented Jun 20, 2015 at 17:35
  • 1
    Thanks, it worked as I upgrade the ipython notebook. I have an additional question: when I double click and open the notebook. If I exit the notebook in browser, will the server close automatically or still running in the background. Commented Jun 21, 2015 at 3:44
  • 1
    No the server won't quit. You have to kill it through the process manager.
    – Matt
    Commented Jun 21, 2015 at 10:29
13
  1. pip install nbopen.
  2. open Automator, create new Application

    • Drag'n drop Run Shell Script
    • Change Pass input to as arguments
    • Copy/paste this script:
    variable="'$1'"
    the_script='tell application "terminal" to do script "nbopen '
    osascript -e "${the_script}${variable}\""
    
  3. Save the new application to Applications directory as nb_open

  4. Right click any ipynb file and select "Open with > Other" and select the nb_open in the Applications folder. Don't forget to check "Always Open With".
  5. Select an ipynb file, get info (command + i) > Open With (select nb_open if not selected already) > Click Change All.... Done.
3
  • This is absolutely wonderful: it is what I came here looking for. The other answer doesn't actually specify this, which is the actual solution. Thank you!
    – NLR
    Commented Apr 29, 2020 at 18:53
  • 3
    Run "python -m nbopen.install_win" to integrate with windows file manager after pip installing nbopen as per the instruction page.. no need for any script or anything.
    – Yogesh G
    Commented May 2, 2020 at 11:57
  • 1
    If you want to close the (zsh) terminal window afterwards use: osascript -e "${the_script}${variable} &! exit\""
    – Graeme
    Commented Jun 5, 2020 at 21:33
6

To "promote" Yogesh's helpful comment to a fully self-contained answer:

Windows 10

In a CMD or PowerShell window with administrative rights (e.g. launched quickly with Win+X, then A), run:

  1. pip install nbopen
  2. python -m nbopen.install_win
  3. Profit!

Double-click on *.ipynb files now starts a new server or reuses an existing instance.

1
  • In my experience, the script is smart enough to not spawn more than one server instance when double-clicking on multiple notebook files. It does not detect any manually launched servers and reuses those. So far, I have not launched a jupyter notebook server manually in months now.
    – ojdo
    Commented Jul 24, 2021 at 12:31
2

One way to open a Jupyter notebook directly by double-clicking on the file is to associate the .ipynb file extension with the jupyter-notebook command. Here's how to do it on a Windows system:

Right-click on the Jupyter notebook file that you want to open. Select "Open with" and then choose "Choose another app". Select "More apps" and then scroll down to the bottom and choose "Look for another app on this PC". Navigate to the directory where the jupyter-notebook.exe file is located (usually in the Scripts subdirectory of your Python installation), and select it. Check the box next to "Always use this app to open .ipynb files" and then click on "OK". Now, when you double-click on an IPython notebook file, it should open directly in the Jupyter notebook.

On a Mac or Linux system, you can set the default application for .ipynb files by using the xdg-mime command. First, determine the full path to the jupyter-notebook executable:

which jupyter-notebook

This will return the path to the executable. Then, use the xdg-mime command to set the default application for .ipynb files:

xdg-mime default jupyter-notebook.desktop application/x-ipynb+json

Replace jupyter-notebook.desktop with the path to the jupyter-notebook executable that you determined earlier. Now, when you double-click on an IPython notebook file, it should open directly in the Jupyter notebook.

0

Great answer by @sahuja for Mac users. A slight modification to have only one terminal opened:

if ps -e | grep "Python" | grep -v "grep" | grep -q "Jupyter/runtime"; then
    /path/to/nbopen "$1"
else
    variable="'$1'"
    the_script='tell application "terminal" to do script "nbopen '
    osascript -e "${the_script}${variable}\""
fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.