40

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?

Community
  • 1
  • 1
an offer can't refuse
  • 4,245
  • 5
  • 30
  • 50
  • "Double click" - are you using some GUI for your Linux? – Jongware Jun 20 '15 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 Jun 20 '15 at 11:41
  • 1
    The question you linked has a solution for ubuntu. Is this solution not working for you? – cel Jun 20 '15 at 11:44
  • @Jongware Are you using no GUI ? I'm using one – an offer can't refuse Jun 20 '15 at 11:46
  • @cel: not really sure what you mean. OP mentions "linux" in passing, and says he *types* other commands. Double-click in a command line? – Jongware Jun 20 '15 at 11:47
  • @buzhidao: I use both (and often at the same time). My question is because there may be different solutions for different Linux GUIs. – Jongware Jun 20 '15 at 11:48
  • @Jongware I'm using Gnome. – an offer can't refuse Jun 20 '15 at 11:50
  • possible duplicate of [Register file extensions / mime types in Linux](http://stackoverflow.com/questions/30931/register-file-extensions-mime-types-in-linux) – Jongware Jun 20 '15 at 11:51
  • @Jongware Thanks for you link, I will read through the solutions. – an offer can't refuse Jun 20 '15 at 11:54
  • 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 Aug 12 '15 at 14:52
  • I would like to add that you can do this natively in macOS with an Automator script. https://stackoverflow.com/a/46995543/4550784 – BadAtLaTeX Oct 28 '17 at 23:41

4 Answers4

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.

Matt
  • 27,170
  • 6
  • 80
  • 74
  • Traceback (most recent call last): File "/usr/local/bin/nbopen", line 3, in 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' – an offer can't refuse Jun 20 '15 at 15:48
  • error occurs, also no response of double click. Although the file icon changes to ipynb – an offer can't refuse Jun 20 '15 at 15:49
  • @buzhidao what version of IPython are you using? You may need to upgrade it for nbopen to work. – Thomas K Jun 20 '15 at 17:35
  • @ThomasK I'm using 1.2.1 – an offer can't refuse Jun 21 '15 at 01:44
  • 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. – an offer can't refuse Jun 21 '15 at 03:44
  • 1
    No the server won't quit. You have to kill it through the process manager. – Matt Jun 21 '15 at 10:29
  • I have another project called [nbmanager](https://github.com/takluyver/nbmanager) which shows you the running notebook servers and lets you stop them. – Thomas K Jun 21 '15 at 20:24
  • @ThomasK Thank you very much. This is very good project but the problem is that I'm using python 2.7 – an offer can't refuse Jun 25 '15 at 14:48
  • It doesn't have to run in the same Python as your notebooks. You can have Python 2 notebooks and run nbmanager on Python 3. – Thomas K Jun 25 '15 at 17:33
11
  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.
tozCSS
  • 5,487
  • 2
  • 34
  • 31
sahuja
  • 151
  • 1
  • 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 Apr 29 '20 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 Kumar Gupta May 02 '20 at 11:57
  • If you want to close the (zsh) terminal window afterwards use: `osascript -e "${the_script}${variable} &! exit\""` – Graeme Jun 05 '20 at 21:33
5

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.

ojdo
  • 8,280
  • 5
  • 37
  • 60
  • 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 Jul 24 '21 at 12:31
1

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.