Majdi Abdeljawad Flah
Majdi Abdeljawad Flah

Reputation: 61

How to use Google Colab to run .py files from Github repositories?

I would like to use Google Colab to accelerate the process of calculation of my deep learning model. However, I cannot run the model directly from the .ipynb file in the Google Colaboratory, since it has several .py functions written separately and then the main program will call them together in another .py file.

One of the proposed solutions consisted of following three steps:

  1. Commit the code on Github
  2. Clone on collab
  3. run this command: !python model_Trainer.py on Colab

I have done steps 1 and 2 successfully, however, I still cannot run the third step. And I am getting the following error: python3: can't open file 'model_trainer.py': [Errno 2] No such file or directory.

Does anyone have a solution to this problem?

I look forward to hearing from you.

Upvotes: 5

Views: 8297

Answers (2)

Jiawei Huang
Jiawei Huang

Reputation: 1

I have the same problem. you can use !pwd to see the current dictionary and cd to change the dictionary which your python files locate. If you wanna run the .py file, you can just use !python example.py to run.

Upvotes: 0

Harshil
Harshil

Reputation: 1000

When you clone a GitHub repo in Colab, it will create a directory for that repo. To run your python script, you must use %cd before using !python.


Example: enter image description here

Upvotes: 13

Related Questions