Checking Installed Packages with List and Freeze
π·οΈ Setting Up Your Python Environment / Package Management with pip
π§ Context Introduction
As you begin working with Python, you will quickly find yourself installing external packages to extend the language's capabilities. Whether you are setting up a new project, troubleshooting a dependency issue, or preparing a deployment, knowing exactly which packages are installed in your environment is essential. Python provides two straightforward commands for this purpose: list and freeze. While they both show installed packages, they serve different needs. This guide will help you understand when and how to use each one.
π¦ What Are Installed Packages?
When you install a package using pip, it is stored in your current Python environment. Over time, your environment can accumulate many packages. Being able to inspect them helps you:
- β Verify that a package was installed successfully
- β Check for outdated or conflicting versions
- β Generate a list of dependencies for sharing with your team
- β Recreate the same environment on another machine
π΅οΈ Using pip list to See Installed Packages
The pip list command displays all packages installed in your current environment along with their version numbers. It is the quickest way to get a human-readable overview.
What it shows: - Package name - Installed version
When to use it: - You want a quick visual check of what is installed - You are troubleshooting and need to confirm a package is present - You are exploring a new environment for the first time
Example output format (inline): - Package β Version - requests β 2.31.0 - flask β 3.0.0 - numpy β 1.26.2
The output is clean and easy to scan, making it perfect for manual inspection.
βοΈ Using pip freeze for Reproducible Environments
The pip freeze command also lists installed packages, but it outputs them in a format that can be saved to a file and used to recreate the exact same environment elsewhere.
What it shows: - Package name - Version number - Output is formatted as package==version (one per line)
When to use it: - You want to generate a requirements.txt file for your project - You need to share your exact environment with a teammate - You are deploying code and need to ensure the same dependencies are installed
Example output format (inline): - requests==2.31.0 - flask==3.0.0 - numpy==1.26.2
Notice the double equals sign (==). This is the standard format used by pip to specify exact version requirements.
π Comparison Table: list vs freeze
| Feature | pip list | pip freeze |
|---|---|---|
| Purpose | Quick visual overview | Generate reproducible dependency list |
| Output Format | Table with columns (Package, Version) | package==version format |
| Best For | Manual inspection and troubleshooting | Creating requirements.txt files |
| Includes Dependencies | Yes, all installed packages | Yes, all installed packages |
| Can Be Used for Installation | No | Yes (via pip install -r requirements.txt) |
π οΈ Practical Use Case: Generating a Requirements File
One of the most common tasks for an engineer is to capture the current environment's dependencies so that others can replicate it. Here is how you would typically use pip freeze:
- Activate your Python environment
- Run pip freeze to see the list of packages
- Redirect the output to a file named requirements.txt
- Share this file with your team or include it in your project repository
The resulting requirements.txt file will contain lines like: - flask==3.0.0 - gunicorn==21.2.0 - requests==2.31.0
Anyone with this file can run pip install -r requirements.txt to install the exact same versions.
β οΈ Important Note: Environment Awareness
Both pip list and pip freeze only show packages installed in the currently active Python environment. If you are using virtual environments (which is highly recommended), you must activate the correct environment first. Otherwise, you might see packages from your global Python installation, which can lead to confusion.
Best practice: - Always activate your project's virtual environment before running these commands - Use pip freeze to generate a requirements.txt file for each project - Avoid relying on your global Python installation for project-specific dependencies
π― Summary
- pip list gives you a human-friendly table of installed packages and versions
- pip freeze provides a machine-friendly format ideal for sharing and recreating environments
- Use pip freeze to generate requirements.txt files for your projects
- Always check which environment is active before running either command
Mastering these two commands will help you keep your Python environments organized, shareable, and reproducibleβa fundamental skill for any engineer working with Python.
This command shows all Python packages currently installed in your environment, with list giving a simple table and freeze producing a format ready for sharing.
π Example 1: List all installed packages
Shows every package name and version currently installed in your active Python environment.
# Run this in your terminal, not in a Python script
pip list
π€ Output: A table of package names and versions, e.g.:
Package Version
---------- -------
pip 24.0
setuptools 69.0.3
π Example 2: Freeze all installed packages
Outputs packages in package==version format, which is used to recreate environments.
# Run this in your terminal
pip freeze
π€ Output: A list of package==version lines, e.g.:
pip==24.0
setuptools==69.0.3
π Example 3: List only outdated packages
Shows packages that have newer versions available on PyPI.
# Run this in your terminal
pip list --outdated
π€ Output: A table of outdated packages with current and latest versions, e.g.:
Package Version Latest Type
---------- --------- --------- -----
requests 2.28.0 2.31.0 wheel
π Example 4: Save freeze output to a file
Creates a requirements.txt file that engineers can share to reproduce the same environment.
# Run this in your terminal
pip freeze > requirements.txt
π€ Output: No terminal output β a file named requirements.txt is created in the current directory
π Example 5: List packages installed in a specific environment
Checks packages inside a virtual environment without activating it first.
# Run this in your terminal (replace "myenv" with your environment name)
myenv/bin/pip list
π€ Output: A table of packages installed only inside that virtual environment, e.g.:
Package Version
---------- -------
numpy 1.26.0
pandas 2.1.0
Comparison Table
| Command | Purpose | Output Format | Best For |
|---|---|---|---|
pip list |
Show all installed packages | Table (Package + Version) | Quick visual check |
pip freeze |
Show packages in shareable format | package==version lines |
Saving to requirements.txt |
pip list --outdated |
Show packages needing updates | Table with current + latest versions | Planning upgrades |
pip freeze > file.txt |
Save freeze output to file | No terminal output | Reproducing environments |
π§ Context Introduction
As you begin working with Python, you will quickly find yourself installing external packages to extend the language's capabilities. Whether you are setting up a new project, troubleshooting a dependency issue, or preparing a deployment, knowing exactly which packages are installed in your environment is essential. Python provides two straightforward commands for this purpose: list and freeze. While they both show installed packages, they serve different needs. This guide will help you understand when and how to use each one.
π¦ What Are Installed Packages?
When you install a package using pip, it is stored in your current Python environment. Over time, your environment can accumulate many packages. Being able to inspect them helps you:
- β Verify that a package was installed successfully
- β Check for outdated or conflicting versions
- β Generate a list of dependencies for sharing with your team
- β Recreate the same environment on another machine
π΅οΈ Using pip list to See Installed Packages
The pip list command displays all packages installed in your current environment along with their version numbers. It is the quickest way to get a human-readable overview.
What it shows: - Package name - Installed version
When to use it: - You want a quick visual check of what is installed - You are troubleshooting and need to confirm a package is present - You are exploring a new environment for the first time
Example output format (inline): - Package β Version - requests β 2.31.0 - flask β 3.0.0 - numpy β 1.26.2
The output is clean and easy to scan, making it perfect for manual inspection.
βοΈ Using pip freeze for Reproducible Environments
The pip freeze command also lists installed packages, but it outputs them in a format that can be saved to a file and used to recreate the exact same environment elsewhere.
What it shows: - Package name - Version number - Output is formatted as package==version (one per line)
When to use it: - You want to generate a requirements.txt file for your project - You need to share your exact environment with a teammate - You are deploying code and need to ensure the same dependencies are installed
Example output format (inline): - requests==2.31.0 - flask==3.0.0 - numpy==1.26.2
Notice the double equals sign (==). This is the standard format used by pip to specify exact version requirements.
π Comparison Table: list vs freeze
| Feature | pip list | pip freeze |
|---|---|---|
| Purpose | Quick visual overview | Generate reproducible dependency list |
| Output Format | Table with columns (Package, Version) | package==version format |
| Best For | Manual inspection and troubleshooting | Creating requirements.txt files |
| Includes Dependencies | Yes, all installed packages | Yes, all installed packages |
| Can Be Used for Installation | No | Yes (via pip install -r requirements.txt) |
π οΈ Practical Use Case: Generating a Requirements File
One of the most common tasks for an engineer is to capture the current environment's dependencies so that others can replicate it. Here is how you would typically use pip freeze:
- Activate your Python environment
- Run pip freeze to see the list of packages
- Redirect the output to a file named requirements.txt
- Share this file with your team or include it in your project repository
The resulting requirements.txt file will contain lines like: - flask==3.0.0 - gunicorn==21.2.0 - requests==2.31.0
Anyone with this file can run pip install -r requirements.txt to install the exact same versions.
β οΈ Important Note: Environment Awareness
Both pip list and pip freeze only show packages installed in the currently active Python environment. If you are using virtual environments (which is highly recommended), you must activate the correct environment first. Otherwise, you might see packages from your global Python installation, which can lead to confusion.
Best practice: - Always activate your project's virtual environment before running these commands - Use pip freeze to generate a requirements.txt file for each project - Avoid relying on your global Python installation for project-specific dependencies
π― Summary
- pip list gives you a human-friendly table of installed packages and versions
- pip freeze provides a machine-friendly format ideal for sharing and recreating environments
- Use pip freeze to generate requirements.txt files for your projects
- Always check which environment is active before running either command
Mastering these two commands will help you keep your Python environments organized, shareable, and reproducibleβa fundamental skill for any engineer working with Python.
Interactive Views
You are currently in π All-in-One mode. Use the tabs at the top to switch to π Theory Only or π» Code Only views.
This command shows all Python packages currently installed in your environment, with list giving a simple table and freeze producing a format ready for sharing.
π Example 1: List all installed packages
Shows every package name and version currently installed in your active Python environment.
# Run this in your terminal, not in a Python script
pip list
π€ Output: A table of package names and versions, e.g.:
Package Version
---------- -------
pip 24.0
setuptools 69.0.3
π Example 2: Freeze all installed packages
Outputs packages in package==version format, which is used to recreate environments.
# Run this in your terminal
pip freeze
π€ Output: A list of package==version lines, e.g.:
pip==24.0
setuptools==69.0.3
π Example 3: List only outdated packages
Shows packages that have newer versions available on PyPI.
# Run this in your terminal
pip list --outdated
π€ Output: A table of outdated packages with current and latest versions, e.g.:
Package Version Latest Type
---------- --------- --------- -----
requests 2.28.0 2.31.0 wheel
π Example 4: Save freeze output to a file
Creates a requirements.txt file that engineers can share to reproduce the same environment.
# Run this in your terminal
pip freeze > requirements.txt
π€ Output: No terminal output β a file named requirements.txt is created in the current directory
π Example 5: List packages installed in a specific environment
Checks packages inside a virtual environment without activating it first.
# Run this in your terminal (replace "myenv" with your environment name)
myenv/bin/pip list
π€ Output: A table of packages installed only inside that virtual environment, e.g.:
Package Version
---------- -------
numpy 1.26.0
pandas 2.1.0
Comparison Table
| Command | Purpose | Output Format | Best For |
|---|---|---|---|
pip list |
Show all installed packages | Table (Package + Version) | Quick visual check |
pip freeze |
Show packages in shareable format | package==version lines |
Saving to requirements.txt |
pip list --outdated |
Show packages needing updates | Table with current + latest versions | Planning upgrades |
pip freeze > file.txt |
Save freeze output to file | No terminal output | Reproducing environments |