Last modified: May 28, 2025 By Alexander Williams
Install Python Packages in Google Colab
Google Colab is a free cloud-based platform for running Python code. It comes with many pre-installed packages. But sometimes, you need to install additional ones.
This guide will show you how to install Python packages in Google Colab. We'll cover different methods like using pip
, conda
, and more.
Table Of Contents
Why Install Packages in Google Colab?
Google Colab has many popular Python packages. But you might need newer versions or special packages. Installing them is easy.
Some reasons to install packages:
- Use the latest version of a package
- Add packages not included by default
- Test experimental features
Method 1: Install with pip
The easiest way is using pip
. Just run this command in a code cell:
!pip install package_name
For example, to install numpy:
!pip install numpy
Collecting numpy
Downloading numpy-1.21.2-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (15.8 MB)
Installing collected packages: numpy
Successfully installed numpy-1.21.2
Note: The !
tells Colab to run a shell command. This works for any Linux command.
Method 2: Install Specific Versions
You can specify a version with ==
:
!pip install pandas==1.3.0
This is useful when you need an exact version for compatibility.
Method 3: Install from Requirements File
For multiple packages, use a requirements.txt
file. First upload it, then run:
!pip install -r requirements.txt
This method is great for reproducing environments. Learn more about installing with requirements.txt.
Method 4: Install with conda
Colab also supports conda
. First install conda, then use it:
!pip install -q condacolab
import condacolab
condacolab.install()
Now you can use conda commands:
!conda install package_name
For complex environments, conda might be better than pip. See our guide on installing with conda.
Method 5: Install from GitHub
For development versions, install directly from GitHub:
!pip install git+https://github.com/user/repo.git
Method 6: Install Local Packages
You can upload and install local packages too:
- Upload the package file (.whl or .tar.gz)
- Install it with pip
!pip install package_file.whl
For more on this, see our guides on .whl files and .tar.gz files.
Common Issues and Solutions
1. Restart Runtime After Install
Some packages need a runtime restart. Go to Runtime > Restart runtime after installing.
2. Check Installed Packages
See what's installed with:
!pip list
3. Upgrade Packages
Use --upgrade
to get the latest version:
!pip install --upgrade package_name
Conclusion
Installing Python packages in Google Colab is simple. The main method is using pip
with !
prefix. For special cases, you can use conda or install from files.
Remember that installed packages don't persist after the session ends. You'll need to reinstall them each time.
Now you're ready to use any Python package in Colab. Happy coding!