5

When finding an interesting Python Jupyter Notebook, such as 02.00-Introduction-to-NumPy.ipynb, I usally have to:

  • download it locally
  • open a shell in the same folder (tip: use SHIFT+RIGHT CLICK+ Open command window here to save 30 second browsing in the different folders) and do jupyter notebook
  • select the right .ipynb file, and finally run the code

Isn't there an easier way to do this?

What is the natural way to open a .ipynb notebook which is online, and run the code, without having to manually download the .ipynb?

Note: the notebook is visible here: https://github.com/jakevdp/PythonDataScienceHandbook/blob/master/notebooks/02.00-Introduction-to-NumPy.ipynb but we can't run the code

Basj
  • 41,386
  • 99
  • 383
  • 673

1 Answers1

3

@jakevdp builds in a nice way to do that, see here. In short, on each page he has an Open in Google Colab button:

@GoogleColab can open any @ProjectJupyter notebook directly from @github!
To run the notebook, just replace "http://github.com " with "http://colab.research.google.com/github/ " in the notebook URL, and it will be loaded into Colab.

Example: 02.00-Introduction-to-NumPy.ipynb becomes: https://colab.research.google.com/github/jakevdp/PythonDataScienceHandbook/blob/master/notebooks/02.00-Introduction-to-NumPy.ipynb

By default, code will run on Colab's distant server, but it's also possible to run it locally, by clicking on top right's Connect to local runtime...:

enter image description here


I personally prefer the MyBinder project as a route. It will open temporary, active sessions with the contents of any Github repo, Github Gists, Gitlab repo, Zenodo archive, Dataverse repo, Datashare archive, Figshare archive, and others. Many repositories already include the necessary configuration files and even put a launch binder button them. Some don't but you can go to the form at MyBinder project and generate a session. That form will also generate a URL that you can use to target the public MyBinder system to open a session alter For example, this person posted the link to open a session for all of Jakes notebooks, you just got to the URL https://mybinder.org/v2/gh/jakevdp/PythonDataScienceHandbook/master?filepath=notebooks%2FIndex.ipynb to tell MyBinder to start a session. Then from the index page that comes up you can click on the link you listed above and run it. Jake included configuration files that MyBinder also recognizes. Note, for some repositories or archives you'll point MyBinder at, it won't have the necessary configuration files and so you can run %pip install <package_name_here> or %conda install <package_name_here> in the current session and continue on running code. Limitations include that you have to be concerned with not sharing anything you wouldn't mind be public, limited resources, and FTP is not allowed to avoid abuse.

Some others to get you started:

Wayne
  • 6,607
  • 8
  • 36
  • 93
  • 1
    Thank you very much @Wayne. I just added a few more details as I was discovering your method, I hope it's ok for you! – Basj Feb 11 '20 at 16:49
  • PS @Wayne: do you know a method which works for any source, not only github? Example: this is a demo .ipynb notebook: https://gget.it/i8ks/helloworld.ipynb. Is there a way to let the browser open it without having to download it and do `jupyter notebook`? – Basj Feb 11 '20 at 17:10
  • Yes, open a Binder session using a `launch binder` button, preferably from a repo that may already have all (or at least most) packages installed needed to run the notebook you are trying to run. Then bring it into the session and use it. For your example, in a notebook cell you can run `!curl -OL https://gget.it/i8ks/helloworld.ipynb`. Or in a terminal on the session run `curl -OL https://gget.it/i8ks/helloworld.ipynb`. Then navigate to the dashboard and run the downloaded notebook. – Wayne Feb 11 '20 at 17:32