amy
amy

Reputation: 352

Saving changes to cloned repo on google colab

I have cloned a github repo which has folders and python files in it. I initially cloned it in C drive, when I run the program, it gives the following error:

import click
ImportError: No module named click

Someone recommended to do pip install click and it didn't work. So, I cloned it using google colab and performed !pip install click and the program eliminated that error. But now I am having another problem. I can access the contents using !cat filename.py and modify it and then run it on google colab. However, how do I save the changes to the file?

PS: I am using Python 2

Thank you.

Upvotes: 1

Views: 1815

Answers (2)

Hari Prasad
Hari Prasad

Reputation: 1364

use %%writefile to save the contents to file back within colab instance.

! cat path_to_file/file.py

copy the content into new cell as following

%%writefile path_to_file/file.py
print("update changes to be done in this cell.")

Upvotes: 0

OneCricketeer
OneCricketeer

Reputation: 191894

It's not recommended to save pip modules into Git repositories. Plus, if it works after installing an external module, there's nothing for you to edit (and cat isn't used to edit files anyway, try !vi)

You should edit a README file describing the runtime requirements for the project as well as provide a common requirements file like so

pip freeze > requirements.txt

In your documentation, mention

pip install -r requirements.txt

Upvotes: 1

Related Questions