Connect Google Colab to a Local Runtime using Jupyter

Dipan Saha
3 min readApr 30, 2023

--

Photo by Ricardo Gomez Angel on Unsplash

Google Colab is a powerful tool that allows you to run Jupyter notebooks in the cloud. However, there may be times when you want to connect Colab to a local runtime. This could be for a number of reasons, such as:

  1. To access files that are stored on your local machine.
  2. To use a specific version of Python or another programming language.
  3. To run code that requires access to hardware resources on your local machine, such as a GPU.

In this tutorial, I shall show you how to connect Google Colab to a local runtime.

Step 1: Install Jupyter.

The first step is to install Jupyter on your local machine. You can do this using the following command:

pip install jupyter

Step 2: Install the Colab Jupyter HTTP-over-WebSocket extension.

The next step is to install the Colab Jupyter HTTP-over-WebSocket extension. This extension allows Colab to connect to a local Jupyter server. You can install the extension using the following commands:

# Install jupyter_http_over_ws
pip install jupyter_http_over_ws

# Enable the extension
jupyter serverextension enable --py jupyter_http_over_ws

Step 3: Start a local Jupyter server and authenticate.

Once you have installed the Colab Jupyter HTTP-over-WebSocket extension, you can start a local Jupyter server by running the following command:

jupyter notebook --NotebookApp.allow_origin='https://colab.research.google.com' --port=8888 --NotebookApp.port_retries=0

Important! Note down the link you get from this screen. You will be using it in the next step.

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.

Conclusion

Hope you found this blog useful! Let me know what you think about this, if you have any suggestion of a topic you would love to see here get in touch.

If you enjoyed the writings leave your claps 👏 to recommend this article so that others can see it.

--

--

Dipan Saha

Cloud Architect (Certified GCP Professional Architect & Snowflake Core Pro)