31

I want to run the notbooks in the following project on Github (located in notebook folder)

https://github.com/n-waves/multifit

The notebooks depend on the other modules, files and data of the whole project, so I can't just open them in google Colab. I can use !git clone ... to make a clone on the space provided by Colab, but then I can't open the notbooks in the browser and run them (like other notebooks run by google Colab).

So, my question is how to run those notebooks in google colab, I would prefer to run them in visual mode (I mean the browser)?

5 Answers 5

93

Open the Github notebook that you want to work with in Google Colab. Change the domain from 'github.com' to 'githubtocolab.com'. The notebook will open in Colab.

Only works with Public repos.

6
  • 4
    Quite a lifehack.
    – optim1st
    Jan 28, 2022 at 13:35
  • 1
    This does not work for notebooks in private repositories. Feb 16, 2022 at 14:28
  • 1
    @EduardoPignatelli Does anything work for private repos?
    – a06e
    Nov 18, 2022 at 9:25
  • 2
    Top 10 craziest things ive seen in my life
    – Katsu
    Jan 18 at 1:23
  • @EduardoPignatelli You just have to give access to private repos in colab . It will ask for authentication or you can set the permission in colab home page
    – Jb-99
    Feb 21 at 14:25
19

Another option is to browse the repository using Colab's UI. If you visit this URL, it will present you with options:
https://colab.research.google.com/
enter image description here

Then you can select your repository:

https://colab.research.google.com/github/n-waves/multifit/blob/master/

After which, you can select the notebook you wish to open.

preview

P.S. Picked this trick up while reviewing this PR for Drake.

P.P.S. I'm not yet sure how to constrain it to a certain folder (PR comment)

4
  • 1
    I dont understand what is next. You select the repo but open a notebook?? Jan 3, 2022 at 12:43
  • 1
    Sorry about that; edited text to clarify "After which, you can select the notebook ..." Jan 5, 2022 at 14:09
  • 3
    This doesn't seem to check out the whole repo- maybe only the local folder? I need resources that are in a peer folder to where the notebook lives in the repo.
    – Robert Sim
    Mar 14 at 4:14
  • @EricCousineau it would be cool if you could add Robert Sim s susggestion as most people will have the need to access other data from the same repo
    – ilam engl
    Aug 23 at 9:37
11

Another way is to add https://colab.research.google.com/github/ before the repository name in the notebook's URL. Let's say I have a Jupyter notebook on Github with the following URL: https://github.com/username/repository/blob/master/notebook.ipynb. To open this notebook in Google Colab, I can change the URL to https://colab.research.google.com/github/username/repository/blob/master/notebook.ipynb. This will open the notebook directly on Colab.

1
  • 1
    This is I believe the simplest and cleanest option
    – Gabriel
    Mar 30 at 22:37
5

A helpful extension is Open in Colab.

This will provide an icon in your browser toolbar that will open the GitHub notebook you're currently viewing in Colab.

(There's no mechanism to load notebooks from the filesystem after !git clone ....)

2

The trick is to copy those notebooks to Google Drive. Extract their FILE_ID, then open them using

https://colab.research.google.com/drive/FILE_ID

I wrote a library to extract FILE_ID easier. It's based on xattr.

Here's an example how to open a multifit notebook. CLS-DE.ipynb

4
  • Thank you! great job! then if I put the whole project in my drive and open a notebook from there, it can identify the paths to the project files?
    – Ahmad
    Jun 27, 2020 at 15:41
  • The notebook will not know about other project files. You need to manually add a cell to load other files, e.g. !npx degit n-waves/multifit -f
    – korakot
    Jun 27, 2020 at 15:52
  • I need the project files beside the notebooks. Could I mount the google drive, then open the notebook as you showed and meanwhile change the current directory (%cd) to the project folder in my drive and run the notebook?
    – Ahmad
    Jun 27, 2020 at 16:38
  • 1
    There are 2 ways to do this. You can store all project files in your drive too. Then %cd to it. Or, what I prefer, is to download from github everytime to the new Colab instance. You may need to !mkdir or %cd a bit too.
    – korakot
    Jun 27, 2020 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.