How to Check Which Python Libraries Are Installed

To check which Python libraries are installed, run pip’s list command through the Python interpreter you use for your project:

python -m pip list

This displays installed package names and versions for that Python environment, not every Python installation on your computer. You can also inspect an individual package, check a notebook or Conda environment, and distinguish installed libraries from modules already loaded by your code.

What an Installed Python Package List Shows

Python libraries are usually installed as distribution packages. Pip reads their installation metadata to report names, versions, and other details.

Keep these distinctions in mind:

  • Packages belong to environments. Your system Python, project virtual environment, and notebook kernel can have different libraries installed.
  • Distribution names and import names can differ. Pillow is the distribution name, but its import name is PIL. Likewise, scikit-learn is imported as sklearn.
  • Standard-library modules are not separate pip packages. Modules such as json, math, and pathlib come with Python and normally do not appear in pip’s inventory.
  • An inventory includes dependencies. It is not limited to packages you explicitly chose to install.

Using pip through a specific Python interpreter is more reliable than invoking a standalone pip executable: it ties the package check to that interpreter rather than whichever pip executable your shell finds first.

How to Check Installed Python Libraries

First, identify the environment that matters for your task.

Where Your Code Runs Which Environment to Check
A terminal-launched script The interpreter used to launch that script
A project virtual environment That project’s environment, not the system installation
An IDE or notebook The selected interpreter or running notebook kernel
A Conda project The project’s active or named Conda environment

Step 1: Identify the Python Interpreter

  1. In your project’s Python session, IDE console, or notebook, run `import sys` followed by `print(sys.executable)`. Terminal commands do not belong at Python’s >>> prompt.
  2. Print the path of the Python executable:
    python -c "import sys; print(sys.executable)"

The result identifies the interpreter you are checking. For a project that uses a virtual environment, the path printed by `sys.executable` should point inside that environment.

The examples here use an executable named python. On macOS or Linux, your executable may be named python3; on Windows, you may use the py launcher. Keep your interpreter choice consistent throughout the checks.

Step 2: List Installed Packages and Versions

  1. Request the package inventory:
    python -m pip list
  2. Read the Package and Version columns. These describe the distributions visible to the selected interpreter.

If your project runs with python3, use:

python3 -m pip list

If you use the Windows Python launcher, use:

py -m pip list

Choose the form that matches how you run your project, not simply whichever command produces the longest list.

These commands inspect the environment; they do not install or upgrade anything. The inventory can include packages installed by tools other than pip, provided their distribution metadata is visible to Python.

Step 3: Inspect a Specific Library

  1. Supply the distribution name to pip’s show command. For example, to inspect Requests:
    python -m pip show requests
  2. Check the relevant fields: – Version: the installed distribution version. – Location: the package installation location. – Requires: its declared package dependencies. – Required-by: installed distributions that declare a dependency on it.

If pip reports that the package was not found, it could not find that distribution’s metadata in the selected environment.

For an editable installation, the output may also identify an editable project location. In that case, the source code can live outside the usual package installation directory.

Step 4: Save the Inventory if Needed

  1. To save the inventory, enter `python -m pip list >` followed by a filename you are comfortable creating or replacing. Shell redirection with > overwrites an existing file.
  2. Save a machine-readable inventory:
    python -m pip list --format=json > installed-packages.json

The saved `python -m pip list` inventory contains package names and versions and can be attached to a bug report or used to compare environments.

If you instead need requirements-file syntax, use:

python -m pip freeze > requirements.txt

Freeze records installed distributions in a requirements-compatible format and normally omits some packaging tools. It includes dependencies, not just your project’s direct requirements, and it is not a dependency solver or a portable lockfile.

Check Virtual Environments, Jupyter, and Conda

Run the environment’s Python executable, %pip in the current kernel, or conda list to inspect the intended environment’s inventory.

An Existing Virtual Environment

You do not have to activate a virtual environment to inspect it. Calling its Python executable directly avoids ambiguity about which environment is selected.

For an existing environment named .venv, run the appropriate command from the directory containing that environment.

On macOS or Linux:

.venv/bin/python -m pip list

On Windows, in PowerShell or Command Prompt:

.\.venv\Scripts\python.exe -m pip list

Replace .venv with your actual environment directory if it has a different name. The returned inventory belongs to that environment’s interpreter.

Do not create a new environment merely to check an existing project’s libraries: a new environment will have its own, different inventory.

A Jupyter Notebook or IPython Session

In a notebook using an IPython-based Python kernel, run this in a code cell:

%pip list

A shell-level pip command can instead resolve to a different installation.

If the inventory is unexpected, identify the kernel’s Python executable:

import sys
print(sys.executable)

If that path is not the environment your project should use, select the intended kernel and run the inventory cell again. A notebook’s environment is determined by its kernel, not merely by the directory containing the notebook file.

A Conda Environment

To list packages in the active Conda environment:

conda list

To inspect an existing environment without activating it, replace myenv with its name:

conda list -n myenv

If you do not know the environment name, list the available environments:

conda env list

Conda’s inventory can include non-Python libraries and other environment components, so it is broader than a Python distribution inventory.

Check Installed Libraries From Python Code

Checks for installed distributions and discoverable modules are useful inside scripts, IDE consoles, and notebooks. They also work when the interpreter has no usable pip module.

List Installed Distributions Without Pip

from importlib.metadata import distributions
installed = sorted(
    (dist.metadata["Name"], dist.version)
    for dist in distributions()
    if dist.metadata["Name"]
)
for name, version in installed:
    print(f"{name}=={version}")

Run this code with the interpreter you want to inspect.

A No module named pip error means pip is unavailable to that interpreter; it does not mean the environment contains no third-party libraries. Reading distribution metadata lets you inspect the environment without installing anything.

Check Whether a Module Can Be Found

To check whether Python can locate a top-level module without importing that module, use its import name:

from importlib.util import find_spec
available = find_spec("requests") is not None
print(available)

A result of True means Python’s import machinery can find the module. A result of False means it cannot find that name on the current import path.

This checks availability, not installation provenance or successful execution. A local Python file can be discoverable without being an installed distribution, and a discoverable package can still fail when imported because of a missing dependency or another initialization error.

Use a top-level name for this lightweight check. Looking up a dotted name can import its parent package.

Confirm the Library Works in the Intended Environment

An installed package is not necessarily the package your code imports.

The final check is to run an import in the actual process that needs the library, then inspect where Python loaded it from.

Verify the Import and File Location

Run this code in your script, IDE console, or notebook:

import sys
import requests
print("Python:", sys.executable)
print("Library:", requests.__file__)

For Requests, successful output identifies both the running interpreter and the imported library’s file location.

Interpret the result carefully:

  • The interpreter path is unexpected: select the intended interpreter or kernel, restart the process if needed, and run the import check again.
  • The library path points to a conflicting file in your project: a local file or directory may be shadowing the installed library. Rename the conflicting item, restart the Python process or kernel, and repeat the import check.
  • The traceback names a different missing module: the requested library may be present while one of its dependencies is missing.
  • The traceback reports a binary or shared-library error: package metadata can exist even though native components cannot load.

This file-location check works for ordinary file-backed packages such as Requests. Some built-in modules and namespace packages do not have a conventional __file__ value.

Check Declared Dependency Consistency

To check whether installed packages have compatible declared dependencies, run:

python -m pip check

A clean result reports:

No broken requirements found.

If pip identifies a missing dependency or an incompatible version, the environment has a dependency issue even if the target package appears in its inventory.

This check does not import every library or test external shared libraries. Once the inventory, interpreter path, and import location match your project, keep your terminal, IDE, and notebook pointed at that environment before installing or upgrading packages.

Frequently Asked Questions

How Do I Check a Library’s Version From Python?

Use importlib.metadata.version() with the distribution name to read its installed version.

from importlib.metadata import PackageNotFoundError, version
try:
    print(version("requests"))
except PackageNotFoundError:
    print("Requests distribution metadata was not found.")

This does not require importing the library itself, and it avoids relying on a __version__ attribute, which not every library provides.

How Do I Show All Packages With pkg_resources?

import pkg_resources
for dist in sorted(
    pkg_resources.working_set,
    key=lambda item: item.project_name.lower(),
):
    print(f"{dist.project_name}=={dist.version}")

This is a legacy setuptools API and may be unavailable in newer environments. Use the standard-library importlib.metadata API for new code rather than adding a dependency on pkg_resources.

How Do I Check Which Python Libraries Are Loaded?

import sys
loaded = sorted(
    name
    for name, module in sys.modules.copy().items()
    if module is not None
)
for name in loaded:
    print(name)

Run this inside the application, notebook, or interpreter session you want to inspect. The list includes standard-library modules, imported dependencies, and submodules, not every installed package.