Skip to main content

Build Status PyPI

pip-check-reqs

It happens: you start using a module in your project and it works and you don’t realise that it’s only being included in your virtualenv because it’s a dependency of a package you’re using. pip-missing-reqs finds those modules so you can include them in the requirements.txt for the project.

Alternatively, you have a long-running project that has some packages in requirements.txt that are no longer actively used in the codebase. The pip-extra-reqs tool will find those modules so you can remove them.

Assuming your project follows a layout like the suggested sample project:

setup.py
setup.cfg
requirements.txt
sample/__init__.py
sample/sample.py
sample/tests/test_sample.py

Basic usage, running in your project directory:

<activate virtualenv for your project>
pip-missing-reqs --ignore-file=sample/tests/* sample

This will find all imports in the code in “sample” and check that the packages those modules belong to are in the requirements.txt file.

Additionally it is possible to check that there are no dependencies in requirements.txt that are then unused in the project:

<activate virtualenv for your project>
pip-extra-reqs --ignore-file=sample/tests/* sample

This would find anything that is listed in requirements.txt but that is not imported by sample.

Sample tox.ini configuration

To make your life easier, copy something like this into your tox.ini:

[testenv:pip-check-reqs]
deps=-rrequirements.txt
commands=
    pip-missing-reqs --ignore-file=sample/tests/* sample
    pip-extra-reqs --ignore-file=sample/tests/* sample

Excluding test files (or others) from this check

Your test files will sometimes be present in the same directory as your application source (“sample” in the above examples). The requirements for those tests generally should not be in the requirements.txt file, and you don’t want this tool to generate false hits for those.

You may exclude those test files from your check using the –ignore-file option (shorthand is -f). Multiple instances of the option are allowed.

Excluding modules from the check

If your project has modules which are conditionally imported, or requirements which are conditionally included, you may exclude certain modules from the check by name (or glob pattern) using –ignore-module (shorthand is -m):

# ignore the module spam
pip-missing-reqs --ignore-module=spam sample
# ignore the whole package spam as well
pip-missing-reqs --ignore-module=spam --ignore-module=spam.* sample

Using pyproject.toml instead of requirements.txt

If your project uses pyproject.toml, there are multiple ways to use pip-check-reqs with it.

One way is to use an external tool to convert pyproject.toml to requirements.txt:

# requires `pip install pdm`
pdm export --pyproject > requirements.txt

# or, if you prefer uv, `pip install uv`
uv pip compile --no-deps pyproject.toml > requirements.txt

Then you can use pip-missing-reqs and pip-extra-reqs as usual.

Another way is to use a requirements.txt file within your pyproject.toml file, for example with the setuptools build backend:

[build-system]
build-backend = "setuptools.build_meta"
requires = [
  "setuptools",
]

[project]
...
dynamic = ["dependencies"]

[tool.setuptools.dynamic]
dependencies = { file = "requirements.txt" }

With Thanks To

Josh Hesketh – who refactored code and contributed the pip-extra-reqs tool.

Wil Cooley – who handled the removal of normalize_name and fixed some bugs.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pip_check_reqs-3.0.0.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pip_check_reqs-3.0.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file pip_check_reqs-3.0.0.tar.gz.

File metadata

  • Download URL: pip_check_reqs-3.0.0.tar.gz
  • Upload date:
  • Size: 19.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.4

File hashes

Hashes for pip_check_reqs-3.0.0.tar.gz
Algorithm Hash digest
SHA256 f0cd0a78cf7da659b3a27191644eb4051b717331ed0c6049ce3db4a5a1d35003
MD5 2db75f0aed1e848cb67c630f18697af9
BLAKE2b-256 955e56ed133c789ba42cb831dad49252c01633027a9f7105a1b0c30938ce5b47

See more details on using hashes here.

File details

Details for the file pip_check_reqs-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: pip_check_reqs-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.4

File hashes

Hashes for pip_check_reqs-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 593d85bdf72715a5ac152fbd3aa25275122a8449856cf4cd14e8b1c63ccbabfd
MD5 896b407437cd2d486c94cff18e2ff02b
BLAKE2b-256 13f3449a613babb751bb6b2c8434bea705075f46fd0ef113f6a04560e58fa998

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

3.0.0 This release

2 files

2.5.6

2 files

2.5.5

2 files

2.5.4

2 files

2.5.3

2 files

2.5.1

2 files

2.5.0

2 files

2.4.4

2 files

2.4.3

2 files

2.4.2

2 files

2.4.0

2 files

2.3.2

2 files

2.3.1

2 files

2.3.0

2 files

2.2.2

2 files

2.2.0

2 files

2.1.1

2 files

2.0.4

2 files

2.0.3

1 file

2.0.1

2 files

2.0

2 files

1.2.1

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page