Jason Sundram
Jason Sundram

Reputation: 12544

Open an ipython notebook via double-click on osx

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?

Upvotes: 28

Views: 20918

Answers (8)

BadAtLaTeX
BadAtLaTeX

Reputation: 704

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.

Upvotes: 16

sahuja
sahuja

Reputation: 171

  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.

Upvotes: 4

flow2k
flow2k

Reputation: 4357

PyCharm now supports Jupyter ipynb files: enter image description here

which is from the documentation https://www.jetbrains.com/help/pycharm/editing-jupyter-notebook-files.html.

But I think this feature is only available in the Professional version now; hopefully it will be added to the Community version in the future.

Upvotes: 1

Aziz Alto
Aziz Alto

Reputation: 20381

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

Upvotes: 16

RobBW
RobBW

Reputation: 61

I have used the command line application 'nbopen' and put it in a Platypus wrapper to get drag'n drop and double click opening on Macos. 'nbopen' is downloadable using 'pip' It works well when used as described above by DanHickstein. Only problem with my code is that it requires the full path to the nbopen command. I know I should be able to use 'which nbopen' somehow but can't get it to work. Heres my Platypus code:

#!/bin/bash
#  Opens ipynb files in a Jupyter Notebook
#  echo $1
#  $1 is the path of the dropped file
/Users/robw/anaconda/bin/nbopen $1
#  Based on an idea from 
#  https://www.quora.com/Is-there-a-straightforward-way-to-open-an-IPython-Notebook-in-Windows-by-double-clicking

Upvotes: 0

DanHickstein
DanHickstein

Reputation: 6948

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...

Upvotes: 3

Martino
Martino

Reputation: 778

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.

Upvotes: 1

cd98
cd98

Reputation: 3532

Look at this link. Put a bash script in the folder where you keep your ipython notebooks and simply double click it to open up a notebook instance. From the link above, the bash script has just:

path=$0             # path is path to this file
cd ${path%/*.*}     # clip off the file name to get directory path and cd
ipython notebook --pylab inline

Finally, you need to chmod u+x the script to make it executable and you're done.

Upvotes: 0

Related Questions