Google Colab in VS Code
Tags: vscode, python
Published: 2022-05-10 19:32:26

You can use [Google Colab](https://colab.research.google.com/) in [VS Code](https://code.visualstudio.com/) . 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](#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](http://jupyter.org/install) 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](https://github.com/googlecolab/jupyter_http_over_ws).
   `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](https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter) 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/83y7j2u4s4ubsaxp39il.png)
   Then Click on `Existing`. Enter the URL from the previous step-4 , you copied.
   ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jl2ivlz8dr8r5wzbe7fx.gif)

\***\*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](https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter) in VS Code .

2. Install [Jupyter](http://jupyter.org/install) on your computer. Than you want to install some modules manually to prevent error in vscode , there are :

- [ptyprocess](https://pypi.org/project/ptyprocess/)
- [ipykernel](https://pypi.org/project/ipykernel/)
- [pyzmq](https://pypi.org/project/pyzmq/)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zlmh8uclygcz0eoyq9cp.png)

--> **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)](https://abujuni.dev)

---

Writer : [Junaid](https://abujun.dev)

Publisher : [Junaid](https://abujun.dev)