{"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":"en","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,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}