
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
| Package | Old Version | New Version |
|---|---|---|
| numpy | 1.24.3 | 1.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
| Error | Cause | Solution | Screenshot Idea |
|---|---|---|---|
| ModuleNotFoundError | Package not installed | Re-run !pip install package_name and restart runtime | Show error in notebook cell |
| pip not recognized | Using system pip | Use %pip install package_name | Highlight %pip command |
| Version conflicts | Multiple versions installed | Uninstall old version: !pip uninstall package_name | Show version list |
| Runtime not updating | Package installed but not loaded | Restart Runtime → Runtime → Restart runtime | Screenshot of restart menu |
Step 6 — Best Practices
- Always restart runtime after installing new packages.
- Use
%pipmagic for reliable installation:
%pip install requests
- Pin package versions to avoid conflicts:
!pip install pandas==2.1.1
- Use
requirements.txtfor 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)
| Package | Install Command | Purpose |
|---|---|---|
| pip | pip install --upgrade pip | Package manager |
| setuptools | pip install setuptools | Build utilities |
| wheel | pip install wheel | Build wheels |
| tqdm | pip install tqdm | Progress bars |
| requests | pip install requests | HTTP requests |
| python-dotenv | pip install python-dotenv | Environment variables |
| rich | pip install rich | Pretty terminal output |
✅ Data Science & Numerical Computing
| Package | pip install |
|---|---|
| numpy | pip install numpy |
| pandas | pip install pandas |
| scipy | pip install scipy |
| sympy | pip install sympy |
| statsmodels | pip install statsmodels |
| pyarrow | pip install pyarrow |
| polars | pip install polars |
| xarray | pip install xarray |
✅ Visualization
| Package | pip install |
|---|---|
| matplotlib | pip install matplotlib |
| seaborn | pip install seaborn |
| plotly | pip install plotly |
| bokeh | pip install bokeh |
| altair | pip install altair |
| pydeck | pip install pydeck |
✅ Machine Learning (Classic)
| Package | pip install |
|---|---|
| scikit-learn | pip install scikit-learn |
| xgboost | pip install xgboost |
| lightgbm | pip install lightgbm |
| catboost | pip install catboost |
| imbalanced-learn | pip install imbalanced-learn |
✅ Deep Learning (Colab Favorites)
| Package | pip install |
|---|---|
| tensorflow | pip install tensorflow |
| keras | pip install keras |
| torch | pip install torch |
| torchvision | pip install torchvision |
| torchaudio | pip install torchaudio |
| fastai | pip install fastai |
| pytorch-lightning | pip install pytorch-lightning |
✅ NLP & LLMs
| Package | pip install |
|---|---|
| nltk | pip install nltk |
| spacy | pip install spacy |
| gensim | pip install gensim |
| transformers | pip install transformers |
| datasets | pip install datasets |
| sentence-transformers | pip install sentence-transformers |
| openai | pip install openai |
| langchain | pip install langchain |
| llama-index | pip install llama-index |
✅ Computer Vision & Images
| Package | pip install |
|---|---|
| opencv-python | pip install opencv-python |
| pillow | pip install pillow |
| scikit-image | pip install scikit-image |
| albumentations | pip install albumentations |
| ultralytics | pip install ultralytics |
| detectron2 | pip install detectron2 |
✅ Audio / Video
| Package | pip install |
|---|---|
| librosa | pip install librosa |
| pydub | pip install pydub |
| moviepy | pip install moviepy |
| soundfile | pip install soundfile |
| ffmpeg-python | pip install ffmpeg-python |
| whisper | pip install openai-whisper |
✅ Web Scraping & Automation
| Package | pip install |
|---|---|
| beautifulsoup4 | pip install beautifulsoup4 |
| lxml | pip install lxml |
| scrapy | pip install scrapy |
| selenium | pip install selenium |
| playwright | pip install playwright |
| fake-useragent | pip install fake-useragent |
✅ Web Apps & APIs
| Package | pip install |
|---|---|
| flask | pip install flask |
| fastapi | pip install fastapi |
| uvicorn | pip install uvicorn |
| django | pip install django |
| streamlit | pip install streamlit |
| gradio | pip install gradio |
| dash | pip install dash |
✅ Databases & Big Data
| Package | pip install |
|---|---|
| sqlalchemy | pip install sqlalchemy |
| psycopg2-binary | pip install psycopg2-binary |
| pymongo | pip install pymongo |
| redis | pip install redis |
| elasticsearch | pip install elasticsearch |
| pyspark | pip install pyspark |
✅ Cloud, DevOps & MLOps
| Package | pip install |
|---|---|
| boto3 | pip install boto3 |
| google-cloud-storage | pip install google-cloud-storage |
| azure-storage-blob | pip install azure-storage-blob |
| mlflow | pip install mlflow |
| wandb | pip install wandb |
| dvc | pip install dvc |
✅ Testing, Debugging & Code Quality
| Package | pip install |
|---|---|
| pytest | pip install pytest |
| unittest2 | pip install unittest2 |
| black | pip install black |
| flake8 | pip install flake8 |
| mypy | pip install mypy |
| pylint | pip 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.

0 Comments