How do I get a list of locally installed Python modules?

113    Asked by NakanoHase in Python , Asked on Sep 4, 2025

How can you get a list of all locally installed Python modules, and what commands or tools make it easy to view them? Learn different ways using pip, pip freeze, or Python’s built-in libraries to check installed packages.

Answered by johnharper

Getting a list of locally installed Python modules is something every developer eventually needs, especially when setting up environments, troubleshooting dependencies, or sharing project requirements. Fortunately, Python offers several easy ways to do this, both from the command line and within a script.

The most common method is using pip, the default Python package manager. Simply run:

  pip list

This will show you all installed packages along with their versions.

If you want the output in a format that can be shared or used to recreate the same environment, you can use:

  pip freeze

This generates a list of packages in a requirements.txt-friendly format, which is perfect for deployment or collaboration.

You can also retrieve the list from within Python itself by using the pkg_resources or importlib.metadata libraries:

import pkg_resources
installed = [pkg.key for pkg in pkg_resources.working_set]
print(installed)

Or, for Python 3.8 and above:

import importlib.metadata
print(importlib.metadata.distributions())

Key Points:

  • pip list → Human-readable list of installed packages.
  • pip freeze → Exact versions in requirements.txt format.
  • Programmatic methods → Useful for scripts or automated tools.
  • Virtual environments → Always check you’re inside the right environment (venv or conda) to avoid confusion.

 In short, use pip list for a quick check, pip freeze for sharing, and Python’s libraries when you need the list inside a program.



Your Answer

Interviews

Parent Categories