Friday, December 27, 2024
Google search engine
HomeLanguagesHow to run Python code on Google Colaboratory

How to run Python code on Google Colaboratory

Prerequisite: How to use Google Colab Google provides Jupyter Notebook like interface to run Python code on online Virtual Machines. In this article, we will see how to run simple Python code on Google Colab. Step #1: Open https://colab.research.google.com/ Step #2: Select New Python3 Notebook Step #3: Start Typing code into the code cells. Import all necessary libraries. Step #4: To add new cell, click on Insert->Code Cell Step #5: To run a particular cell, select the cell and press Ctrl + ENTER keys.

Code cells under process

Output after successful run

Installing any particular module –

We might need to install some external modules while working on some projects in Google Colab. By default not all the required modules are being pre-installed in Google Colab. So how can we install them using pip command ?

Step – 1 : Open a new blank code cell.

Step – 2 : Try to import that module and check if it is pre-installed or not.

 

Here I am trying to import the Streamlit module which doesn’t come pre-installed in collab. So we need to install it externally using pip.

Step – 3 : Now we will install our required missing module/package using the following syntax.

!pip install <module_name>

 

Step 4 : After successful execution of the cell try to reimport it or run the previous cell to check if it has installed properly or not.

 

Now we can see the green check mark on the left side of the cell , which indicates it has executed properly without any error and the module has been installed properly.

RELATED ARTICLES

Most Popular

Recent Comments