Open an ipython notebook via double-click on osx

18,451

Solution 1

Use Pineapple application for opening and working on your IPython/Jupyter notebooks. It is pretty cool.

Update:

Now there is nteract, which is a new jupyter-like Desktop app. After installing it, make it the default app for opening .ipynb files. Then just double-click any notebook to start it right away.

nteract geojson

Solution 2

I have found a nice way using Automator (Oct. 2017; with information from here):

  1. open Automator and create a new Application menu
  2. to add Run Shell Script drag and drop it from the list; might need these settings Shell: /bin/bash and Pass input: as arguments run shell script
  3. insert the code below; if necessary adjust the path to jupyter

Code

#!/bin/sh
variable="'$1'"
the_script='tell application "terminal" to do script "/usr/local/bin/jupyter notebook '
osascript -e "${the_script}${variable}\""
  1. save the script as an application (!)
  2. try to open a .ipynb file and change the default app to this newly created one.

notes

  1. This will open a terminal and run the jupyter notebook command, such that you can interrupt and stop the notebook-server from there. Also note that you cannot test the app like that in Automator, but need to add the Get Specified Finder Items and insert some test notebook there (just for testing purposes).

As pointed out in the comments, there are two more notes:

  1. To avoid spamming your browser history with notebooks, you can start your notebooks in incognito/private mode: Run jupyter notebook in incognito window

  2. If you want to run notebooks in one server and don't mind an extra tool, Sachit Nagpal has pointed out (thank you), that one could also use nbopen. To use this workflow just replace "/usr/local/bin/jupyter notebook ' with "nbopen '. Any other tool should work alike.

Solution 3

  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.

Solution 4

The application posted here worked pretty well for me: http://bioequity.org/2013/11/16/ipynbviewer/ You also need to download iTerm2, as described on that page.

Note that this doesn't work if there are spaces in the filename, but you can modify it so that it works with spaces in the filename. Control-click on the iPyNbViewer.app and select "Show package contents". Edit the file Contents/Resources/Scripts/main.scpt. Change three instances of "POSIX path" to "quoted form of POSIX path". Now it will work with spaces in the filename.

To set all of your .ipynb files to open with the app, you'll need to Get Info (command-I) on one of the files and select the iPyNbViewer app to open all .ipynb files.

It would be great if this was the default behavior of double-clicking on an iPython notebook file...

Solution 5

I came up with a way of doing it on Ubuntu. (It works for me but I can take no responsibility). It's explained here. In a nutshell, you need to create a new MIME type, then write a script that works as the app that launches them:

#!/bin/bash
netstat -tln |grep "8902"
# if not found - equals to 1, start it
if [ $? -eq 1 ]
then
ipython notebook / --no-browser --port=8902 &
sleep .5
fi
xdg-open http://localhost:8902/notebooks$1

This always opens the notebook server on port 8902, but first checks whether there is already a server running, and, if so, uses it. Then you can use ubuntu tweak to select your script as a default application for the MIME type "IPython Notebook" you just created. Not very elegant, but worth it, in my opinion.

Share:
18,451
pythonBOI
Author by

pythonBOI

I like data visualization, music, Python, and scientific programming. Track me down all over the internet at http://about.me/jsundram

Updated on July 05, 2022

Comments

  • pythonBOI
    pythonBOI almost 2 years

    I've downloaded a couple of ipython notebooks, and I'd like to open them in browser tabs without navigating to the directory I've downloaded them to and running ipython notebook notebook_name.ipynb.

    I realize this probably means I'm lazy, but it seems like a common use case to me. Am I missing something obvious?