LinuxCommandLibrary

pip-inspect

Inspect installed Python packages

TLDR

Inspect the current environment

$ pip inspect
copy

Inspect and save output to a file
$ pip inspect > [environment_report.json]
copy

Inspect only locally installed packages (not global)
$ pip inspect --local
copy

Inspect only user-installed packages
$ pip inspect --user
copy

Inspect packages in a specific path
$ pip inspect --path [path/to/environment]
copy

Inspect with verbose output (Note: the -v flag can be repeated to increase verbosity)
$ pip inspect [[-v|--verbose]]
copy

SYNOPSIS

pip-inspect [OPTIONS] [PACKAGE...]

PARAMETERS

PACKAGE...
    Optional. One or more package names to inspect. If omitted, information about all installed packages may be displayed, depending on other options.

--list
    Lists all installed packages in the environment.

--files <PACKAGE>
    Shows a list of files installed by the specified package.

--dependencies <PACKAGE>
    Displays the direct and transitive dependency tree for the specified package.

--reverse-dependencies <PACKAGE>
    Shows which packages in the environment depend on the specified package.

--paths
    Includes installation paths in the output for packages or files.

--json
    Outputs the results in machine-readable JSON format.

--env <PATH>
    Specifies the path to a Python environment (e.g., a virtual environment) to inspect instead of the current one.

--freeze
    Outputs installed packages in a format similar to pip freeze, suitable for requirements files.

--report
    Generates a detailed report on the entire Python environment, including conflicts and detailed package metadata.

--version
    Shows the program's version number and exits.

--help
    Displays a help message and exits.

DESCRIPTION

pip-inspect is a powerful command-line tool, part of the packaging-inspect project,
designed to provide detailed insights into Python packages installed in a given environment.

It goes beyond basic pip list or pip show commands by offering a more comprehensive view,
including package files, direct and transitive dependencies, and potential conflicts.

This tool is invaluable for debugging installation issues, understanding the composition of a virtual environment,
or auditing package integrity. It can operate on specified packages or list all installed packages,
offering various output formats for easy parsing and analysis.

Its primary goal is to make inspecting Python environments more robust and informative
for developers, system administrators, and CI/CD pipelines.

CAVEATS

pip-inspect is not a built-in pip command and requires separate installation via
pip install packaging-inspect.

It may have limitations when inspecting non-standard Python installations or environments
where package metadata is not fully compliant with modern packaging standards.

Its output can be extensive, particularly for large environments or
when requesting detailed reports, requiring careful parsing or filtering.

<B>USE CASES</B>

pip-inspect is highly versatile for various scenarios:
Debugging: Rapidly identify missing files, incorrect package versions, or circular dependencies that cause application failures.
Auditing: Verify the contents of a Python environment for security compliance, licensing adherence, or to ensure only approved packages are present.
Environment Replication: While not directly a replication tool, its detailed output can inform the creation of precise requirements.txt or similar dependency specification files.

<B>INSTALLATION</B>

To use pip-inspect, it must be installed. This can be done via pip:

pip install packaging-inspect

It is recommended to install it within a virtual environment to avoid conflicts with system-wide Python packages.

HISTORY

The packaging-inspect project, which introduced pip-inspect, emerged from the need
for more sophisticated introspection tools for Python environments.

While pip itself provides basic listing and showing capabilities,
developers and system administrators often required deeper insights into
dependency graphs, installed files, and potential conflicts.

pip-inspect was developed to fill this gap, offering a more robust and
detailed view into Python package installations, evolving with Python's packaging ecosystem.

SEE ALSO

pip(1), pipdeptree(1), pip show(1), pip list(1)

Copied to clipboard