{"id":9749,"library":"flake8-requirements","title":"flake8-requirements","description":"flake8-requirements is a plugin for the flake8 static analysis tool that checks for missing or unused package requirements in Python projects. It helps maintain clean and accurate dependency lists by comparing imported modules against entries in requirements files (e.g., `requirements.txt`) or `pyproject.toml`. The current version is 2.3.0, and its release cadence is generally tied to bug fixes, new features, or compatibility updates for `flake8`.","status":"active","version":"2.3.0","language":"en","source_language":"en","source_url":"https://github.com/arkq/flake8-requirements","tags":["flake8","linter","requirements","dependencies","static analysis","developer tools"],"install":[{"cmd":"pip install flake8-requirements","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"This library is a plugin for flake8 and requires it to run.","package":"flake8","optional":false}],"imports":[],"quickstart":{"code":"#!/bin/bash\n# Create a dummy project for demonstration\nmkdir my_project\ncd my_project\n\necho \"import requests\\nprint('Hello')\" > app.py\necho \"requests\" > requirements.txt\n\n# Install flake8 and the plugin\npip install flake8 flake8-requirements\n\n# Run flake8 with the plugin\nflake8 .\n\n# Example of a missing dependency error (R001)\necho \"import unknown_lib\\nimport requests\" > app.py\nflake8 .\n\n# Example of an unused dependency error (R002)\necho \"requests\\nunused_lib\" > requirements.txt\necho \"import requests\" > app.py\nflake8 .","lang":"bash","description":"After installing `flake8-requirements`, it automatically integrates with `flake8`. Simply run `flake8` in your project directory. The plugin will check your imports against your `requirements.txt` (or a file specified by `--requirements-file`) and report missing (R001) or unused (R002) dependencies."},"warnings":[{"fix":"Ensure your project runs on Python 3.8 or newer. Update your flake8 configuration to use `--always-assume-pip-installed` if you previously used the old flag. Review your dependencies for any R003 issues, which must now be handled manually.","message":"Version 2.0.0 introduced significant breaking changes, including dropping Python 2 support (requiring Python 3.8+). The `--ignore-unregistered-requirements` option was renamed to `--always-assume-pip-installed`, and the R003 error code (multiple declarations) was removed.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Always specify the correct path to your requirements file using the `--requirements-file` option (e.g., `flake8 --requirements-file requirements/prod.txt`) or ensure your `pyproject.toml` is configured correctly if using that format.","message":"By default, `flake8-requirements` looks for `requirements.txt` in the current working directory. If your requirements file is named differently or located elsewhere (e.g., `requirements/prod.txt`, `pyproject.toml`), the plugin will not find it, leading to incorrect checks or an error about a missing file.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For packages that are legitimately required but trigger R002, consider adding them to a development-specific requirements file that is not checked, or ignore the specific R002 error for those packages if you're certain they are needed.","message":"The plugin may produce false positives for 'R002 Unused dependency' when packages are not directly imported but are used indirectly (e.g., via entry points, `setuptools` hooks, development tools, or for configuring external services).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Simplify complex requirements entries where possible. For advanced cases, you might need to manually verify the dependencies or use the `--always-assume-pip-installed` option carefully. Check the project's GitHub issues for known parsing limitations.","message":"The parser for requirements files might struggle with complex or non-standard entries (e.g., VCS URLs like `git+https://...`, editable installs `file:.`, local paths, or specific environment markers) leading to `R004 Invalid requirements file format` or missed checks.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Add `<package_name>` to your `requirements.txt` (or equivalent file) or ensure that the correct requirements file is being checked with `--requirements-file`.","cause":"The Python module `<package_name>` is imported in your source code but is not listed in the requirements file `flake8-requirements` is checking.","error":"R001 Missing dependency: <package_name>"},{"fix":"Verify if `<package_name>` is truly unused. If so, remove it from your requirements file. If it's used indirectly (e.g., via a framework, dev tool, or as a plugin), you may need to ignore this specific error or reconsider your dependency strategy.","cause":"The package `<package_name>` is listed in your requirements file, but `flake8-requirements` could not detect any imports or uses of it in your source code.","error":"R002 Unused dependency: <package_name>"},{"fix":"Examine the requirements file (especially the line indicated by the error if available) and correct any syntax errors or non-standard entries. Refer to `pip`'s documentation on requirements file format.","cause":"There is a line in your requirements file that `flake8-requirements` cannot parse correctly according to `pip`'s requirements file format.","error":"R004 Invalid requirements file format"},{"fix":"Create a `requirements.txt` file in your project's root directory, or use the `--requirements-file path/to/your/reqs.txt` option to point to the correct file location and name.","cause":"`flake8-requirements` could not find the default `requirements.txt` file in the current directory or the file specified by the `--requirements-file` option.","error":"ERROR: flake8-requirements: The requirements file 'requirements.txt' does not exist."}]}