DEV Community

Cover image for 3 Lines to Use VSCode(codeserver) on Google Colab
0xkoji
0xkoji

Posted on

6

3 Lines to Use VSCode(codeserver) on Google Colab

colabcode is an awesome python package since it allows us to use VSCode(codeserver) on Google Colab/Kaggle with only 3 lines.

GitHub logo abhishekkrthakur / colabcode

Run VSCode (codeserver) on Google Colab or Kaggle Notebooks

ColabCode

license PyPI version python version

Installation

$ pip install colabcode
Enter fullscreen mode Exit fullscreen mode

Run code server on Google Colab or Kaggle Notebooks.

Getting Started

ColabCode also has a command-line script. So you can just run colabcode from command line.

colabcode -h will give the following:

usage: colabcode [-h] --port PORT [--password PASSWORD] [--mount_drive]

ColabCode: Run VS Code On Colab / Kaggle Notebooks

required arguments:
  --port PORT          the port you want to run code-server on

optional arguments:
  --password PASSWORD  password to protect your code-server from unauthorized access
  --mount_drive        if you use --mount_drive, your google drive will be mounted
Enter fullscreen mode Exit fullscreen mode

Else, you can do the following:

# import colabcode
$ from colabcode import ColabCode
Enter fullscreen mode Exit fullscreen mode
# run colabcode with by default options.
$ ColabCode()
Enter fullscreen mode Exit fullscreen mode
# ColabCode has the following arguments:
# - port: the port you want to run code-server on, default 10000
# - password: password to protect your code server from being accessed by someone else.
#
Enter fullscreen mode Exit fullscreen mode

3lines

!pip install colabcode
from colabcode import ColabCode
ColabCode(port=10000)
Enter fullscreen mode Exit fullscreen mode

Tha's it. jupyter notebook will show you a ngrok url to access VSCode.

Let me explain about those 3 lines a little bit.

Install PyPI package

As I mentioned, we need to install colabcode to use VSCode on Google Colab. The first line is to install the package.
Pretty straight forward.

!pip install colabcode
Enter fullscreen mode Exit fullscreen mode

Run VSCode via colabcode

If you know python a little bit, these 2 lines are pretty easy to understand. from xxx import yyy is for importing a package. Then, the second is to create an instance. Done lol.

from colabcode import ColabCode
ColabCode(port=10000)
Enter fullscreen mode Exit fullscreen mode

I would like to introduce a couple of parameters we can use to you.
ColabCode() can take a couple of arguments.

From https://github.com/abhishekkrthakur/colabcode/

optional arguments:
  --password PASSWORD  password to protect your code-server from unauthorized access
  --mount_drive        if you use --mount_drive, your google drive will be mounted
Enter fullscreen mode Exit fullscreen mode

As you can see, port is required and the above arguments are optional. If you want to share your VSCode on Colab, maybe password may be useful.

How to Use

python

Screen Shot 2020-09-11 at 10.42.54 AM.png

As you can see, what we will need to do is to open Terminal from the left corner icon. Then execute python test.py.
If you want to change the editor theme, you can do it by clicking Gear icon and select a theme.

Screen Shot 2020-09-11 at 10.48.15 AM.png

nodejs

As you know, Google Colab is for python. However, with VSCode you can use nodejs. The version of nodejs is out of date, v8.11.3. But if you want to do something quickly with nodejs, this may be useful.

Screen Shot 2020-09-11 at 10.55.29 AM.png

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Eliminate Context Switching and Maximize Productivity

Pieces.app

Pieces Copilot is your personalized workflow assistant, working alongside your favorite apps. Ask questions about entire repositories, generate contextualized code, save and reuse useful snippets, and streamline your development process.

Learn more