DEV Community

Cover image for Google Colab in VS Code
Junaid
Junaid

Posted on

Google Colab in VS Code

You can use Google Colab in VS Code . Now , You can learn how to setup Google Colab in VS Code.

There are two ways to do it :

  1. Colab connecting to local runtime in VS Code
  2. Installing Jupiter and google.colab modules

Colab connecting to local runtime in VS Code

  1. Install Jupyter on your local machine.

  2. Install and enable the jupyter_http_over_ws jupyter extension (one-time)
    The jupyter_http_over_ws extension is authored by the
    Colaboratory team and available on GitHub.
    pip install jupyter_http_over_ws
    jupyter serverextension enable --py jupyter_http_over_ws

  3. Start server and authenticate
    New notebook servers are started normally, though you will need to set a flag to explicitly trust WebSocket connections from the Colaboratory frontend.
    jupyter notebook \ --NotebookApp.allow_origin='https://colab.research.google.com' \ --port=8888 \ --NotebookApp.port_retries=0
    Once the server has started, it will print a message with the initial backend URL used for authentication. Make a copy of this URL as you'll need to provide this in the next step.

  4. Connect to the local runtime
    In Colaboratory, click the "Connect" button and select "Connect to local runtime...". Enter the URL from the previous step in the dialog that appears and click the "Connect" button. After this, you should now be connected to your local runtime.

  5. Install Jupyter Extension in VS Code.

  6. Setup colab in VS Code.
    Press F1 to open command palette , and type Jupyter: Specify Jupyter server for connections than select that option.
    Image description
    Then Click on Existing. Enter the URL from the previous step-4 , you copied.
    Image description

**Yahoo!** , You connected colab to VS Code. You can use all modules that you use in colab.

Here we have Full Advantages , No Disadvantages.

😵 This is the Long method to install and setup in VS Code.
But second way is very easy.


Installing Jupiter and google.colab modules

This is very east to setup from fist one. Here we have Advantages and Disadvantages , there are :

Advantages - Full use of colab in VS Code.

Disadvantages - google.colab module will be not supported to some computer or python versions in this method.

Ready To Go -->

  1. Install Jupyter Extension in VS Code .

  2. Install Jupyter on your computer. Than you want to install some modules manually to prevent error in vscode , there are :

Image description

--> DONE ! , you setup is completed.

😎 YA! , This was very very easy .

Now , Open your project and get into it!

There methods are tested and expreienced by Me (Junaid)


Writer : Junaid

Publisher : Junaid

Top comments (2)

Collapse
 
kenclint profile image
kenclint

Hi there,

For step 3 of Colab connecting, what server are you referring to starting and authenticating? The Jupyter server? If so, could you walk through steps 3 and 4?

Thanks!

Collapse
 
junaid_dev profile image
Junaid • Edited

Answers

  1. Creating a local server (local runtime):
  2. - Install Jupyter
  3. - pip install jupyter_http_over_ws
  4. - jupyter serverextension enable --py jupyter_http_over_ws to enable jupyter to run a local host server.
  5. - Start Server : jupyter notebook \ --NotebookApp.allow_origin='https://www.example.com' \ --port=8081

ola! Done!

Simple Explanation

This post tells about that how to connect google colab to your local computer and connect jupyter to VS Code.

TESTED AND VERIFIED By Junaid.