28

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?

Jason Sundram
  • 12,225
  • 19
  • 71
  • 86
  • 1
    I agree that it is a very basic feature. I would need it too for my collaborators that are not programmers but with who I would like to share my notebooks. – jvtrudel May 11 '15 at 22:32
  • This question is answered here: http://stackoverflow.com/questions/30953227/double-click-to-open-an-ipython-notebook – Vasco Feb 25 '16 at 11:21
  • Just added my answer to this [it works like a charm](https://stackoverflow.com/a/54489884/11004008) – sahuja Feb 02 '19 at 05:48

8 Answers8

16

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

Aziz Alto
  • 19,057
  • 5
  • 77
  • 60
  • 3
    Fantastic stand-alone apps. I'd say they are perfect for new learners to scientific computing. Perhaps advanced users would want something that cooperates with their existing Anaconda installations? – tslmy Jun 08 '17 at 09:51
16

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.

Community
  • 1
  • 1
BadAtLaTeX
  • 614
  • 1
  • 9
  • 22
  • You're welcome. I want to add a **note** here: I have just experienced a little problem with this, where I would double click a `*.ipynb`file but the script wouldn't end and even get a timeout. This seemed to be caused by some circumstances the terminal application was in (long idle?). Since I could not figure out which these were, but only accidentally fix it by trying to open a terminal manually, could someone with more experience give a hint ? – BadAtLaTeX Aug 02 '18 at 12:50
  • Does this start a new server each time? Is there a way to launch the file via the already running server? And only begin new server if no jupyter server is already running – Sachit Nagpal Nov 05 '18 at 22:14
  • @SachitNagpal yes, this will start one terminal and jupyter notebook kernel each time. There should be a way to achieve this with some shell-command. Basically you can tell the terminal to run any (e.g. bash-) script. However, I am not too experienced in bash scripting, but you would probably have to run `jupyter notebook list` (or `ps` ?) to find the running kernel and some ID. Then you could distinguish and use some command to attach the file / path to the running kernel. You might want to ask a separate question for the shell command to open files in running kernels and look up `grep`. – BadAtLaTeX Nov 06 '18 at 14:07
  • Thanks @gr4nt3d for explaining how this could be done. For now, I have been able to achieve this using nbopen (github.com/takluyver/nbopen) – Sachit Nagpal Nov 06 '18 at 18:35
  • 1
    Thanks. This is a better way than installing some other packages. – frankliuao Feb 27 '19 at 20:16
  • I came across the problem, that my browser history was full of notebooks (even if I just had a -with this- conveniently quick look). See [this](https://stackoverflow.com/questions/48787973/) for incognito/private notebooks. – BadAtLaTeX Jul 03 '19 at 09:58
4
  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
3

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

DanHickstein
  • 6,588
  • 13
  • 54
  • 90
  • I developed this tool iPyNbViewer. Thanks to Dan's suggestion, I have updated all three instances of `quoted form of POSIX path`. Enjoy! – laviex Apr 27 '16 at 15:14
1

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.

Martino
  • 729
  • 6
  • 18
1

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.

flow2k
  • 3,999
  • 40
  • 55
0

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.

cd98
  • 3,442
  • 2
  • 35
  • 51
0

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
RobBW
  • 61
  • 6