0

I have just get my hands dirty with VSCode's extension Google Colab (by Google).

While I can connect to google servers for running Jupyter Notebooks (.ipynb files), Is there a way to use VSCode directly on .py files of my project and execute them on Google servers.

Note that I dont want to use the command !python <filename.py> from my notebooks to run the .py files of my project, I want to run them directly with VSCode just like I am able to with Jupyter Notebook.

2
  • An aside about your statement, "Note that I dont want to use the command !python <filename.py> from my notebooks to run the .py files of my project": while there are the rare occasions that can be useful, you primarily should be using %run <filename.py> to run Python script files from inside a running notebook. This magic is more full-featured and offers better handling of the stdout and stderr than sending it off to a temporary shell instance like !python would. The best feature for development is %run -i which allows you to run the script attached to the current namespace. See... Commented Dec 1, 2025 at 16:29
  • <continued> here in the documentation for magic %run for more information. Commented Dec 1, 2025 at 16:31

2 Answers 2

0

Yes, edit .py files in VSCode and run them on Google servers via the Google Colab extension, like Jupyter notebooks.​

Setup Steps:

  • Install Jupyter and Google Colab extensions in VSCode.

  • Open .py or .ipynb file, select Colab kernel, and sign in with Google.

  • Connect to Colab runtime (CPU/GPU/TPU) for remote execution.​​

Limitations: No direct Google Drive mount or userdata access in VSCode.

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

1 Comment

Did you try this solution? Are you able to select a Colab kernel in a .py file?
0

Yes, based on what this GitHub repo says: https://github.com/googlecolab/colab-vscode

Copied from the repo's README.md:

  1. Install VS Code.

  2. Install the Colab extension from either the Visual Studio Marketplace or Open VSX.

  3. Open or create a notebook file.

  4. When prompted, sign in.

  5. Click Select Kernel > Colab > Auto Connect.

  6. 😎 Enjoy!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.