Registry / devops / pip-licenses

pip-licenses

JSON →
library5.5.5pypypiunverified

pip-licenses is a command-line interface (CLI) tool designed to efficiently list the software licenses of Python packages installed via pip. It is actively maintained with regular updates, aligning with the release cadence of `pip` itself. The current version is 5.5.5.

pip install pip-licenses
INSTALL
IMPORT
SIG · PIP-LICENSES
P
pip-licenses
devopspythonv5.5.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

The primary usage of `pip-licenses` is through its command-line interface. After installation, simply running `pip-licenses` will display a table of all non-system Python packages and their associated licenses in your current environment. Common options include `--with-system` to include system packages, `--fail-on` to exit with an error if a specific license is detected, `--format` for different output types (e.g., json, html, markdown), and `--summary` to get a count of packages per license.

import os # Install pip-licenses and a sample package (if not already installed) # os.system('pip install Django pip-licenses') # Basic usage: list all installed package licenses print("\n--- Basic License List ---") os.system('pip-licenses') # Include system packages like pip and setuptools print("\n--- With System Packages ---") os.system('pip-licenses --with-system') # Fail if a specific license (e.g., AGPL) is found print("\n--- Fail on AGPL (example, might exit with error) ---") # For demonstration, we use a common permissive license (MIT) to show failure. # In a real scenario, you'd check for restrictive licenses like AGPL. # This command will exit with a non-zero code if MIT is found. # os.system('pip-licenses --fail-on "MIT License" --partial-match') # Output in JSON format print("\n--- Output in JSON Format (first 1000 chars) ---") json_output = os.popen('pip-licenses --format=json').read() print(json_output[:1000]) # Get a summary of licenses by count print("\n--- License Summary ---") os.system('pip-licenses --summary')
pip-licenses --version
Debug
Known issues
breaking`pip-licenses` versions 4.x and 5.x have dropped support for older Python versions. Specifically, 4.x discontinued support for Python 3.7, and versions 5.x require Python >=3.9 (dropping 3.8 support). Users on older Python environments should use an earlier `pip-licenses` version (e.g., `<4.0` for Python 3.7).
fix
Ensure your Python environment is 3.9 or newer, or install a compatible older version of `pip-licenses` (e.g., `pip install 'pip-licenses<4.0'` for Python 3.7).
affects: 4.0.0+, 5.0.0+
breakingWhen upgrading from `pip-licenses` 3.x to 4.x or later, the `PTable` dependency was removed. You must explicitly uninstall `PTable` to avoid conflicts.
fix
After upgrading `pip-licenses`, run `pip uninstall -y PTable`.
affects: 4.0.0+
breakingIn version 3.5.0, the separator for displaying multiple licenses for a single package changed from a comma to a semicolon. This can affect scripts parsing the output.
fix
Update any parsing logic to expect semicolons as separators for multiple licenses.
affects: 3.5.0+
gotchaBy default, `pip-licenses` ignores system-level packages (like `pip`, `setuptools`, and its own dependencies) to focus on user-installed project dependencies.
fix
To include system packages in the output, use the `--with-system` option: `pip-licenses --with-system`.
affects: All
gotcha`pip-licenses` is primarily a CLI tool and does not offer a direct programmatic API for import. If you are looking for a library for programmatic license detection, consider `pip-licenses-lib`, which is a separate fork providing library functionality.
fix
For programmatic access, use the `pip-licenses-lib` package (e.g., `pip install pip-licenses-lib`) and import `piplicenses_lib` functions.
affects: All
breakingSupport for PEP 639 (SPDX License Expressions) was added, and with `pip-licenses 5.5.0`, the `--from=all` output now includes the `License-Expression` value. This change affects the structure of the output, particularly when using `--from=all`.
fix
Review and update any scripts that parse the `--from=all` output to account for the new `License-Expression` field.
affects: 5.5.0+
Errors
Common errors & fixes
pip-licenses: command not found
The pip-licenses executable is not in your system's PATH, either because the tool was not installed correctly or the Python environment's script directory is not included in PATH.
fix
Ensure pip-licenses is installed in your active Python environment using `pip install -U pip-licenses` and that your environment's scripts directory (e.g., `venv/bin` or `venv/Scripts`) is included in your system's PATH. You may need to reactivate your virtual environment or open a new terminal.
AttributeError: 'PathDistribution' object has no attribute 'project_name'
This error arises from compatibility issues between pip-licenses and newer versions of Python or pip, where internal distribution object structures have changed, and pip-licenses is attempting to access an outdated attribute.
fix
Upgrade pip-licenses to the latest available version using `pip install -U pip-licenses`. This issue was resolved in newer versions of the library, often with release candidates for immediate fixes.
pip-licenses displays 'UNKNOWN' for a package license
The package's license is not declared in a standard location (e.g., Trove Classifiers or package Metadata) or in a format that pip-licenses can automatically parse.
fix
Run `pip-licenses --from=mixed` to instruct pip-licenses to first check Trove Classifiers and then fallback to package Metadata. If the license is still 'UNKNOWN', you might need to manually inspect the package's metadata or repository for the license information.
UnicodeEncodeError when running pip-licenses
This error occurs when pip-licenses attempts to output characters (e.g., in license texts or package metadata) that cannot be encoded using the current terminal's or system's default character encoding.
fix
Set your terminal or system's `LANG` and `LC_ALL` environment variables to a UTF-8 locale (e.g., `export LANG=en_US.UTF-8` and `export LC_ALL=en_US.UTF-8` on Linux/macOS) before executing the pip-licenses command.
pip-licenses not working correctly with specific Python versions (e.g., Python 3.7)
The installed version of pip-licenses is incompatible with your current Python environment. For example, pip-licenses 4.x dropped support for Python 3.7 earlier than its end-of-life.
fix
Install a compatible version of pip-licenses for your Python environment. For Python 3.7, use `pip install 'pip-licenses<4.0'`. For Python 2.7, use `pip install 'pip-licenses<2.0'`.
Upgrade
Version history
5.5.5latest on PyPI · released Mar 28, 2026
Audit
Dependencies
prettytablerequiredUsed for formatting the output of license information in a tabular display.
wcwidthrequiredImplicitly required by prettytable for proper column width calculation in various terminals.
tomlirequiredUsed for reading pyproject.toml files on Python versions < 3.11.
Agent activity
3 hits · last 30 days
node
2
Resources
pip-licenses — pip install pip-licenses · libregistry