Ahmad
Ahmad

Reputation: 9658

How can I run notebooks of a Github project in Google Colab?

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)?

Upvotes: 38

Views: 45944

Answers (6)

Ethar
Ethar

Reputation: 1

I ran into this issue recently and cloning the repo did not solve the issue. What I did after cloning is I copied the cloned folder's path and then %cd it in the notebook, it worked just fine!

Upvotes: 0

Reza
Reza

Reputation: 141

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.

Upvotes: 14

Jaya Raghavendra
Jaya Raghavendra

Reputation: 1577

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.

Upvotes: 112

Eric Cousineau
Eric Cousineau

Reputation: 2004

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)

Upvotes: 20

korakot
korakot

Reputation: 40828

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

Upvotes: 2

Bob Smith
Bob Smith

Reputation: 38579

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

Upvotes: 6

Related Questions