5

I am trying to get some open source software working. It uses things that I don't have on my system (pytorch for example) and so I thought that I could try to run it on Google Colab.

When I tried to do it though, there are some python scripts that I have to run after cloning a directory from a github repository. I guess I can't run another python script from inside a Jupyter Notebook, and so I suppose that I'm trying to do something with Colab that it isn't designed to do?

Is there something available that is more like a terminal, but using the software, GPUs etc. that are available on Colab?

3 Answers 3

6

You can run any shell command from jupyter-like environment (which includes colab) using ! in code cell, for example

!ls

Would list all files in colab's cwd. To run python script you could do:

!python script.py

It works just like terminal (it might be python3, not sure how it's setup un colab)

Sign up to request clarification or add additional context in comments.

Comments

3

You can call your script too.

!python script.py

But you need to put the script there, probably by git clone or direct uploading.

1 Comment

You'll get a richer notebook experience using the %run magic command for running a python script, see here. As for getting the file, you can directly curl or use wget to bring in the script if it is public, too, see here.
1

As Wayne mentions in the comment korakot's answer, you can use the magic command

%run 'script.py'

This also allows you to do e.g. run in the notebook's namespace by using the -i parameter

%run -i 'script.py'

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.