Google Colab and VS Code are the most popular editor tools used by many Python developers and Researchers to develop different tech solutions or systems (especially in Machine Learning & Data Science).
Many Python developers and Data scientists know how to use Google Colab, but do you know that you can set up a VS Code on Google Colab and use it as an editor the same way as in your local machine?
In this article, you will learn
1.Open Colab Notebook
The first step is to launch a new colab notebook in your Google Colab and you can rename the file as you want.
For example, run_vscode.ipynb
2.Install colabcode python package.
To use Google Colab with VS Code (code server), you need to install the colabcode python package. This is an awesome open-source python package developed by Abhishek Thakur.
To install the package, run the following command in your notebook cell.
!pip install colabcode
3.Import ColabCode
The next step is to import ColabCode class from the package.
from colabcode import ColabCode
4.Create an instance of ColabCode
After importing the ColabCode, you need to create an instance of ColabCode and set the following arguments.
ColabCode(port=10000)
5.Start the Code Server
After running the ColabCode instance, it will start the server and show the link to access the code server.
You need to click the link and it will open in a new tab.
Now you can take advantage of a full-fledged code editor and run different experiments on the Colab VM.
Note: If you check on your Colab Notebook, you will observe the cell that runs the ColabCode instance is continuously running. Don't close your Colab notebook unless you want to close the code server that runs VS Code.
After launching the code server, the following tips will help you start using VS Code on Google Colab.
1.Open Terminal
To open the terminal on VS Code that runs on Google Colab, use the following shortcut command
Ctrl + Shift + `
2.Change Theme
You can change the theme of the editor by clicking the setting icon (bottom-left corner) and then click "Color Theme". It will open a popup window with different theme options you can select.
3.Run Python File
You can create a python file by clicking the "File" section on the sidebar and then select a "New File" tab.
In the following example, you will see how to run a simple python file that trains a machine-learning algorithm to classify iris flowers into three species (setosa, versicolor, or virginica) and then make a prediction.
Congratulations 👏👏, you have made it to the end of this article! I hope you have learned something new. You can set up VS Code on Google Colab and take your coding to the next level.
You can also use the colabcode python package on the Kaggle platform to run VS Code. You just need to follow the same steps mentioned above.
If you learned something new or enjoyed reading this article, please share it so that others can see it. Until then, see you in the next post!
You can also find me on Twitter @Davis_McDavid.
And you can read more articles like this here.
Want to keep up to date with all the latest in python? Subscribe to our newsletter in the footer below!