How do I get a list of locally installed Python modules?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
The fastest way to list every installed Python package is pip list. For a requirements-file-ready format, use pip freeze. If you need the list inside a running Python script, the importlib.metadata module (Python 3.8+) is the modern, recommended approach. Each method serves a different use case, so the right choice depends on whether you need a quick terminal check, a reproducible environment snapshot, or programmatic access.
Using pip on the Command Line
pip list
pip list prints every installed package with its version in a human-readable table:
Output:
You can filter for outdated packages with:
This shows the current version, the latest available version, and the installation type, which is useful during dependency audits.
pip freeze
pip freeze produces output in the package==version format that pip install -r understands directly:
Output:
To snapshot your environment into a requirements file:
A teammate or CI pipeline can then reproduce the exact same environment with pip install -r requirements.txt.
pip show (Single Package)
When you need details about one specific package rather than the full list:
Output:
The Requires and Required-by fields are especially helpful for understanding dependency chains before removing or upgrading a package.
Listing Packages Inside a Python Script
importlib.metadata (Recommended for Python 3.8+)
The importlib.metadata module is part of the standard library and replaces the older pkg_resources approach:
This is faster than pkg_resources because it reads metadata lazily from .dist-info directories instead of eagerly scanning the entire working set at import time.
pkg_resources (Legacy)
For codebases stuck on Python 3.7 or earlier, pkg_resources from setuptools still works:
Be aware that pkg_resources has a measurable import-time cost (it scans all installed distributions on first import), so avoid it in performance-sensitive startup paths.
pkgutil (All Importable Modules)
pkgutil.iter_modules() lists every importable module on sys.path, including standard library modules and namespace packages that are not "installed packages" in the pip sense:
Use this when you need to discover every module Python can import, not just those installed through pip.
Conda Environments
If you use Anaconda or Miniconda, conda list replaces pip list for packages installed through conda:
For a cross-format export that includes both conda and pip packages:
This YAML file captures the conda channel, the exact package builds, and any pip-installed packages inside the environment.
Comparison of Methods
| Method | Command / Code | Output Format | Best For |
pip list | pip list | Human-readable table | Quick terminal overview |
pip freeze | pip freeze | package==version | Requirements files, CI reproducibility |
pip show | pip show <name> | Detailed single-package info | Dependency chain inspection |
importlib.metadata | Python script | Programmatic (name, version) tuples | Modern scripts, fast metadata access |
pkg_resources | Python script | Programmatic string list | Legacy Python 3.7 codebases |
pkgutil | Python script | Module name list | Discovering all importable modules |
conda list | conda list | Table with channel and build info | Anaconda/Miniconda environments |
Virtual Environments and Scope
The list of installed packages depends entirely on which Python environment is active. Always activate your virtual environment before running any listing command:
Running pip list outside a virtual environment shows system-wide packages, which rarely reflects what your project actually uses.
Common Pitfalls
Mixing system Python with virtual environments. Running pip list without activating a venv shows system packages. Your project may depend on a package that exists system-wide but is missing from the project's own environment. Always check inside the activated venv.
Using pip freeze with globally installed tools. If you freeze a system Python that has linters, formatters, and CLI tools installed globally, your requirements.txt will include packages your application does not need. Use virtual environments to keep project dependencies isolated.
Relying on pkg_resources in new code. pkg_resources is not deprecated yet, but importlib.metadata is faster and has no external dependency. New projects should prefer importlib.metadata.
Forgetting --user installs. Packages installed with pip install --user go into a user-local directory and may not appear in a virtualenv's pip list. Check pip list --user if a package seems missing.
Assuming pip freeze and pip list show the same packages. pip freeze omits pip itself, setuptools, and wheel by default. pip list shows everything. This difference trips up developers who expect the two outputs to be identical.
Summary
pip listgives you a quick overview of all installed packages in the active environment.pip freeze > requirements.txtcreates a reproducible snapshot for deployment and collaboration.importlib.metadata.distributions()is the modern, performant way to enumerate packages inside Python code.- Always activate your virtual environment before listing packages to avoid confusion between system and project dependencies.
- For Conda users,
conda env exportcaptures both conda and pip packages in a single file.

