Install Python Packages Permanently in Colab : 4 Steps Only

Install Python Packages Permanently in Colab

Most of the packages in colab are not permanently installed. You have to first execute the pip install command each time when you want to use the package. In this post you will know how to install python packages permanently in colab through steps.

Steps to Install Python Packages Permanently in Colab

Lets know all the steps you will use to install python package permanently in colab.

Step 1 : Import the required library

In the first step you will import all the required library.

import os, sys
from google.colab import drive

Step 2: Mount the Google Drive

In the next step you will mount your Google Drive. It will ask for the Google account perminssion. Select the acount you want to give permision.

drive.mount('/content/drive')
colab_path = '/content/notebooks'
os.symlink('/content/drive/My Drive/Colab Notebooks', colab_path)
sys.path.insert(0,colab_path)
Connect the google drive
Giving permission for the google drive
Giving permission for the google drive

Step 3: Install the package

After mounting and setting the path of installation of hte package lets install the package. To do this you have to install the package in the specified path. For example I want to install the numpy package then you will run the below command to install the package.

!pip install --target=$colab_path numpy

Step 4: Restart the session

After installing the package restart the session. Don’t again mount the google drive. Now if you will execute and import the installed package then you will not get the modulenotfound error for that package.

import numpy

Conclusion

If you are getting frustration for installing the python package in colab every time then using this post you will be able to permanently install the python package in the google colab.

I hope you have liked this tutorial. If  you have got any query or suggestions then you can contact us for more help.

Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for signup. A Confirmation Email has been sent to your Email Address.

Something went wrong.

Meet Sukesh ( Chief Editor ), a passionate and skilled Python programmer with a deep fascination for data science, NumPy, and Pandas. His journey in the world of coding began as a curious explorer and has evolved into a seasoned data enthusiast.
 
Thank you For sharing.We appreciate your support. Don't Forget to LIKE and FOLLOW our SITE to keep UPDATED with Data Science Learner