Power User

Google COLAB local runtime ASAP

Don’t wait for a single code block to send a signal to Google’s servers and back just to print a word.

Hursh Gupta's Notes

--

You’ve used Google COLAB haven’t you?

When you are starting out, you will find that it is an excellent Jupyter notebook (assuming that you have used Jupyter before). But the problem with it is that if you connect to a hosted runtime for minor programming. It’s a pain to wait for 1–2 seconds for each code execution. (Unless you are implementing some machine learning).

So, if you just want to learn some python programming, algorithms and stuff.

You have to use this!

The Actual Thing

You must have python and pip installed and functional on your machine before proceeding…

You can actually follow Google’s walkthrough which is already very easy to understand. But I will help you anyway.

Select the local runtime option from the top right corner of the interface.

When you “connect to a local runtime”, you will be shown this next

If you click on the “these instructions”, you will get to a page with all the required commands, but in essence. This is what you have to do. First open a command-promt or a Powershell if on Windows.

  • Run this command to install jupyter notebook.
pip install notebook
  • Install and enable jupyter_http_over_ws (so that you can share the runtime via a websocket, on colab)
pip install jupyter_http_over_wsjupyter serverextension enable --py jupyter_http_over_ws

Now your system is capable of sharing the runtime with colab.

But, here is a troublesome part. Every time, you want to use the local runtime, you will have to run this in a command prompt

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

So, what you can do instead is create a batch file and use it to start the runtime whenever required.

Finally, (after running the command) you have to copy the url with the token as shown below

The URL that needs to be copied.

And then paste it on that dialogue box we started with.

Hurray! You have just started using COLAB on your local runtime. Go ahead and execute some code.

Notice the (local) here.

So, there you have it. And later on, I will also show you how I have setup a powershell script for myself to automate some of my tasks which includes starting up this COLAB runtime AFAP (that sounded so wrong!).

Stay tuned for that. Cheers!

--

--

Hursh Gupta's Notes

I do anything that thrills me. I learn anything that intrigues me. I write about anything that interests me. And lastly, some random emojis 💀🔥🤡🗿