How to connect VS Code to Google Colab?

Method 1: Using ColabCode (Without SSH)

# Mount Google Drive if you want to.
from google.colab import drive
drive.mount('/content/drive')
!pip install colabcodefrom colabcode import ColabCode
ColabCode(port=10000, password=”your_password_here”)

Method 2: Using Colab_SSH

# Mount Google Drive if you want to.
from google.colab import drive
drive.mount('/content/drive')
# Install colab_ssh on google colab.
!pip install colab_ssh --upgrade
from colab_ssh import launch_ssh_cloudflared, init_git_cloudflared
launch_ssh_cloudflared(password="your_password_here")
# Prevent Colab run-time to end.
import time
while True:
time.sleep(300)
  1. Download Cloudflared (Argo Tunnel) as suitable to your system and store it where ever you like. Also, copy the path to it.
  2. Once done, open up the “SSH config” file in a text editor like Notepad.
    For windows, you can find it under: “C:\Users\Your_User_Name\.ssh\config”. In case the file is not present, jump to the 4th step.
  3. Replace “<PUT_THE_ABSOLUTE_CLOUDFLARE_PATH_HERE>” with the path you copied in step 1 and save this code in the config file.
Host *.trycloudflare.com
HostName %h
User root
Port 22
ProxyCommand <PUT_THE_ABSOLUTE_CLOUDFLARE_PATH_HERE> access ssh — hostname %h
  1. To connect Colab and VS code next time, just run the code in Colab and follow steps 5 to step 10 discussed above.
  2. You will need to install the Github Copilot extension each time you connect. You can do this either by VS Code UI or by running this command in the VS Code terminal.
code --install-extension github.copilot
code --install-extension github.copilot --install-extension ms-toolsai.jupyter --install-extension ms-python.python
GitHub.copilot
ms-python.python
ms-toolsai.jupyter
#!/usr/bin/env bashcat extensions.txt | while read extension || [[ -n $extension ]];do
code --install-extension $extension --force
done
# Allow permission
!chmod 755 installext.sh
./installext.sh

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Minting Harmoonies NFT On MetaMask

In 2017, my internship experience in France was a Eureka moment for me.

Create CRUD API Using Golang and MongoDB

Top Code Editors

Building Productivity: FLASH flash cards Pt. 2

Where Software Development interest started

One use case for TPL

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Satpal Singh Rathore

Satpal Singh Rathore

ML Engineer

More from Medium

Digital Platform Innovations for Development Impacts

Creating an App that Connects Driving Directions and Weather Data

How to Add a Static Image to a Django App

Rolling in the deep with Deepnote