{"id":3211,"library":"pip-licenses","title":"pip-licenses","description":"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.","status":"active","version":"5.5.5","language":"python","source_language":"en","source_url":"https://github.com/raimon49/pip-licenses","tags":["licenses","cli","compliance","dependencies","pypi"],"install":[{"cmd":"pip install pip-licenses","lang":"bash","label":"Install or Upgrade"},{"cmd":"pip uninstall -y PTable","lang":"bash","label":"Required when upgrading from pip-licenses 3.x"}],"dependencies":[{"reason":"Used for formatting the output of license information in a tabular display.","package":"prettytable"},{"reason":"Implicitly required by prettytable for proper column width calculation in various terminals.","package":"wcwidth"},{"reason":"Used for reading pyproject.toml files on Python versions < 3.11.","package":"tomli"}],"imports":[],"quickstart":{"code":"import os\n\n# Install pip-licenses and a sample package (if not already installed)\n# os.system('pip install Django pip-licenses')\n\n# Basic usage: list all installed package licenses\nprint(\"\\n--- Basic License List ---\")\nos.system('pip-licenses')\n\n# Include system packages like pip and setuptools\nprint(\"\\n--- With System Packages ---\")\nos.system('pip-licenses --with-system')\n\n# Fail if a specific license (e.g., AGPL) is found\nprint(\"\\n--- Fail on AGPL (example, might exit with error) ---\")\n# For demonstration, we use a common permissive license (MIT) to show failure.\n# In a real scenario, you'd check for restrictive licenses like AGPL.\n# This command will exit with a non-zero code if MIT is found.\n# os.system('pip-licenses --fail-on \"MIT License\" --partial-match')\n\n# Output in JSON format\nprint(\"\\n--- Output in JSON Format (first 1000 chars) ---\")\njson_output = os.popen('pip-licenses --format=json').read()\nprint(json_output[:1000])\n\n# Get a summary of licenses by count\nprint(\"\\n--- License Summary ---\")\nos.system('pip-licenses --summary')\n","lang":"python","description":"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."},"warnings":[{"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).","message":"`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).","severity":"breaking","affected_versions":"4.0.0+, 5.0.0+"},{"fix":"After upgrading `pip-licenses`, run `pip uninstall -y PTable`.","message":"When upgrading from `pip-licenses` 3.x to 4.x or later, the `PTable` dependency was removed. You must explicitly uninstall `PTable` to avoid conflicts.","severity":"breaking","affected_versions":"4.0.0+"},{"fix":"Update any parsing logic to expect semicolons as separators for multiple licenses.","message":"In 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.","severity":"breaking","affected_versions":"3.5.0+"},{"fix":"To include system packages in the output, use the `--with-system` option: `pip-licenses --with-system`.","message":"By default, `pip-licenses` ignores system-level packages (like `pip`, `setuptools`, and its own dependencies) to focus on user-installed project dependencies.","severity":"gotcha","affected_versions":"All"},{"fix":"For programmatic access, use the `pip-licenses-lib` package (e.g., `pip install pip-licenses-lib`) and import `piplicenses_lib` functions.","message":"`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.","severity":"gotcha","affected_versions":"All"},{"fix":"Review and update any scripts that parse the `--from=all` output to account for the new `License-Expression` field.","message":"Support 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`.","severity":"breaking","affected_versions":"5.5.0+"}],"env_vars":null,"search_vec":"'5.5.5':47 'activ':30 'align':35 'cadenc':39 'cli':13,49 'command':10 'command-lin':9 'complianc':50 'current':44 'depend':51 'design':15 'effici':17 'instal':25 'interfac':12 'licens':3,6,21,48 'line':11 'list':18 'maintain':31 'packag':24 'pip':2,5,27,41 'pip-licens':1,4 'pypi':52 'python':23 'regular':33 'releas':38 'softwar':20 'tool':14 'updat':34 'version':45 'via':26","created_at":"2026-04-11T09:25:46.217957+00:00","updated_at":"2026-04-16T18:02:05.882884+00:00","problems":[{"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.","cause":"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.","error":"pip-licenses: command not found"},{"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.","cause":"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.","error":"AttributeError: 'PathDistribution' object has no attribute 'project_name'"},{"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.","cause":"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.","error":"pip-licenses displays 'UNKNOWN' for a package license"},{"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.","cause":"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.","error":"UnicodeEncodeError when running pip-licenses"},{"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'`.","cause":"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.","error":"pip-licenses not working correctly with specific Python versions (e.g., Python 3.7)"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"pip-licenses","cli_version":"pip-licenses 5.5.5","type":"library","homepage":null,"github":"https://github.com/raimon49/pip-licenses","docs":null,"changelog":null,"pypi":"https://pypi.org/project/pip-licenses/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops","testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-04-11","next_check":"2026-07-10","install_tag":null}}