Sharing is caring!

How to Install Any Python Package in Google Colab

Introduction

Working in Google Colab is amazing for Python projects, but you’ll often need extra libraries like Pandas, TensorFlow, or BeautifulSoup. Installing packages in Colab is slightly different from your local machine because each notebook runs on a temporary virtual machine.

In this guide, you’ll learn how to install any Python package in Google Colab, with step-by-step screenshots, code examples, and troubleshooting tips. By the end, you’ll be able to install packages confidently and avoid common errors.


Step 1 — Using pip to Install Packages

Google Colab allows you to run shell commands directly with !. The easiest way to install a package is using pip:

# Install a package
!pip install package_name

# Example: Install requests
!pip install requests

Tip: Use -q for quiet mode to reduce output clutter:

!pip install -q requests

Step 2 — Installing Specific Versions

Sometimes, a project requires a specific version of a library:

# Install TensorFlow version 2.13
!pip install tensorflow==2.13

Step 3 — Upgrading Packages

Keep your packages up-to-date:

# Upgrade a package
!pip install --upgrade numpy
PackageOld VersionNew Version
numpy1.24.31.25.0

Step 4 — Installing from GitHub or Local Files

From GitHub:

!pip install git+https://github.com/username/repository.git

From Google Drive (local file):

from google.colab import drive
drive.mount('/content/drive')

!pip install /content/drive/MyDrive/package.whl

Step 5 — Common Errors & Troubleshooting

ErrorCauseSolutionScreenshot Idea
ModuleNotFoundErrorPackage not installedRe-run !pip install package_name and restart runtimeShow error in notebook cell
pip not recognizedUsing system pipUse %pip install package_nameHighlight %pip command
Version conflictsMultiple versions installedUninstall old version: !pip uninstall package_nameShow version list
Runtime not updatingPackage installed but not loadedRestart Runtime → Runtime → Restart runtimeScreenshot of restart menu

Step 6 — Best Practices

  1. Always restart runtime after installing new packages.
  2. Use %pip magic for reliable installation:
%pip install requests
  1. Pin package versions to avoid conflicts:
!pip install pandas==2.1.1
  1. Use requirements.txt for reproducibility:
!pip install -r requirements.txt


Popular Packages Installation Examples

# Data Analysis
!pip install pandas matplotlib seaborn

# Machine Learning
!pip install scikit-learn tensorflow torch

# Web Scraping
!pip install requests beautifulsoup4 selenium

✅ Core & Utilities (Almost always preinstalled, but good to know)

PackageInstall CommandPurpose
pippip install --upgrade pipPackage manager
setuptoolspip install setuptoolsBuild utilities
wheelpip install wheelBuild wheels
tqdmpip install tqdmProgress bars
requestspip install requestsHTTP requests
python-dotenvpip install python-dotenvEnvironment variables
richpip install richPretty terminal output

✅ Data Science & Numerical Computing

Packagepip install
numpypip install numpy
pandaspip install pandas
scipypip install scipy
sympypip install sympy
statsmodelspip install statsmodels
pyarrowpip install pyarrow
polarspip install polars
xarraypip install xarray

✅ Visualization

Packagepip install
matplotlibpip install matplotlib
seabornpip install seaborn
plotlypip install plotly
bokehpip install bokeh
altairpip install altair
pydeckpip install pydeck

✅ Machine Learning (Classic)

Packagepip install
scikit-learnpip install scikit-learn
xgboostpip install xgboost
lightgbmpip install lightgbm
catboostpip install catboost
imbalanced-learnpip install imbalanced-learn

✅ Deep Learning (Colab Favorites)

Packagepip install
tensorflowpip install tensorflow
keraspip install keras
torchpip install torch
torchvisionpip install torchvision
torchaudiopip install torchaudio
fastaipip install fastai
pytorch-lightningpip install pytorch-lightning

✅ NLP & LLMs

Packagepip install
nltkpip install nltk
spacypip install spacy
gensimpip install gensim
transformerspip install transformers
datasetspip install datasets
sentence-transformerspip install sentence-transformers
openaipip install openai
langchainpip install langchain
llama-indexpip install llama-index

✅ Computer Vision & Images

Packagepip install
opencv-pythonpip install opencv-python
pillowpip install pillow
scikit-imagepip install scikit-image
albumentationspip install albumentations
ultralyticspip install ultralytics
detectron2pip install detectron2

✅ Audio / Video

Packagepip install
librosapip install librosa
pydubpip install pydub
moviepypip install moviepy
soundfilepip install soundfile
ffmpeg-pythonpip install ffmpeg-python
whisperpip install openai-whisper

✅ Web Scraping & Automation

Packagepip install
beautifulsoup4pip install beautifulsoup4
lxmlpip install lxml
scrapypip install scrapy
seleniumpip install selenium
playwrightpip install playwright
fake-useragentpip install fake-useragent

✅ Web Apps & APIs

Packagepip install
flaskpip install flask
fastapipip install fastapi
uvicornpip install uvicorn
djangopip install django
streamlitpip install streamlit
gradiopip install gradio
dashpip install dash

✅ Databases & Big Data

Packagepip install
sqlalchemypip install sqlalchemy
psycopg2-binarypip install psycopg2-binary
pymongopip install pymongo
redispip install redis
elasticsearchpip install elasticsearch
pysparkpip install pyspark

✅ Cloud, DevOps & MLOps

Packagepip install
boto3pip install boto3
google-cloud-storagepip install google-cloud-storage
azure-storage-blobpip install azure-storage-blob
mlflowpip install mlflow
wandbpip install wandb
dvcpip install dvc

✅ Testing, Debugging & Code Quality

Packagepip install
pytestpip install pytest
unittest2pip install unittest2
blackpip install black
flake8pip install flake8
mypypip install mypy
pylintpip install pylint

✅ One-Line “Install Everything Useful” (Colab Friendly)

pip install numpy pandas matplotlib seaborn scikit-learn tensorflow torch transformers datasets opencv-python fastapi gradio streamlit tqdm requests

🔥 Pro Tip (Very Important for Colab)

To search ANY Python package instantly:

pip search package_name

To see what’s already installed:

pip list

How to install any python package in google colab using

How to install any python package in google colab windows 10

Pip install Google Colab

Google Colab packages list

Pip install google colab error

Pip install Google Colab in Jupyter

How to install Google Colab in Python

Google Colab install package permanently


FAQ

Q1: How do I install a package permanently in Google Colab?
A: Colab runs on temporary VMs. Use requirements.txt or rerun installation each session.

Q2: Why do I get ModuleNotFoundError?
A: Restart the runtime after installing a package.

Q3: Can I install Python 2 packages?
A: No, Colab only supports Python 3.

Q4: How to install from GitHub?
A: !pip install git+https://github.com/user/repo.git

Q5: Is %pip better than !pip?
A: Yes, it ensures proper installation in Colab notebooks.

Q6: How to check if a package is installed?
A: Use !pip show package_name

Q7: How to uninstall a package?
A: !pip uninstall package_name

Q8: Can I install packages from local files?
A: Yes, upload .whl or .tar.gz to Colab or Google Drive.

Q9: Why do some packages fail to install?
A: Some need system dependencies not available in Colab. Consider local setup.

Q10: How to upgrade all packages?
A: Use !pip list --outdated then upgrade individually.

Q11: Can I use Conda?
A: Conda is possible but manual; %pip is simpler.

Q12: How to avoid version conflicts?
A: Pin versions in requirements.txt or use == in pip install.


Conclusion

Installing Python packages in Google Colab is easy if you know the right commands. With step-by-step visuals, code examples, and troubleshooting tips, you can now install any package quickly and avoid common issues.

CTA: Try installing your packages today and start building amazing Python projects in Colab!

Visual Tip: End with a screenshot of a fully working notebook running your installed packages successfully.

Categories: Python

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *