{"id":487,"library":"flake8","title":"Flake8","description":"Flake8 is a modular source code checker that wraps PyFlakes, pycodestyle, and Ned Batchelder's McCabe script. It runs all these tools with a single command, displaying a merged output of warnings. As of version 7.3.0, it is actively maintained with releases as necessary, often driven by bug fixes and new features.","status":"active","version":"7.3.0","language":"python","source_language":"en","source_url":"https://github.com/pycqa/flake8","tags":["linter","code quality","static analysis","pep8","pyflakes","mccabe","python"],"install":[{"cmd":"pip install flake8","lang":"bash","label":"Install Flake8"}],"dependencies":[{"reason":"Checks for unused imports and variables, contributing 'F' error codes.","package":"pyflakes","optional":false},{"reason":"Checks for PEP 8 style guide violations, contributing 'E' and 'W' error codes.","package":"pycodestyle","optional":false},{"reason":"Checks for cyclomatic complexity, contributing 'C90' error codes.","package":"mccabe","optional":false},{"reason":"Requires Python >=3.9 as of Flake8 7.2.0. Flake8's parsing capabilities are tied to the Python version it runs on.","package":"python","optional":false}],"imports":[],"quickstart":{"code":"flake8 .","lang":"bash","description":"To check all Python files in the current directory and its subdirectories. You can also run it via `python -m flake8 .` to ensure the correct Python environment is used."},"warnings":[{"fix":"Review your Flake8 configuration and remove these options if present. Adjust your exclusion patterns using `--exclude` or `exclude` in your config file if you previously relied on doctest-specific exclusions.","message":"Flake8 7.0.0 removed the `--include-in-doctest` and `--exclude-from-doctest` options.","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Remove `--diff` from your CI/local scripts. Validate your `.flake8`, `setup.cfg`, or `tox.ini` files for correct error codes and ensure all `--extend-config` paths are valid. Upgrade your Python interpreter to at least 3.8.1.","message":"Flake8 6.0.0 removed the `--diff` option. It also became stricter, producing errors for invalid codes specified in configuration files or if the file specified in `--extend-config` does not exist. Additionally, Python 3.8.1 or newer is now required.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Before upgrading to a new major version, carefully read the official release notes and migration guides. Test your Flake8 configuration and any custom plugins in a separate environment.","message":"Major releases (e.g., 3.0, 4.0, 5.0, 6.0, 7.0) historically include large-scale refactoring, 'subtly breaking CLI changes,' and breaking changes to its plugin interface. Always review release notes for new major versions.","severity":"breaking","affected_versions":"All major version upgrades"},{"fix":"Ensure Flake8 is installed and executed using the same Python version that your project code targets. For example, use `python3.10 -m pip install flake8` and then `python3.10 -m flake8 .`","message":"Flake8's ability to correctly parse Python code is dependent on the Python version it's installed and run with. If you are checking code written with newer Python language features (e.g., Python 3.10's structural pattern matching), Flake8 needs to be installed on a Python 3.10 interpreter to understand those features.","severity":"gotcha","affected_versions":"All"},{"fix":"When troubleshooting unexpected Flake8 behavior, first check command-line arguments, then project configuration files (in order of `.flake8`, `setup.cfg`, `tox.ini`), and finally default settings. Ensure no command-line options are inadvertently overriding your desired configuration.","message":"Flake8 options can be specified on the command-line, or in configuration files (`.flake8`, `setup.cfg`, `tox.ini`). Command-line options always take precedence over configuration file settings. This can lead to unexpected behavior if not understood.","severity":"gotcha","affected_versions":"All"},{"fix":"Use `# noqa` sparingly and only for very specific, justified cases. Prefer to fix the underlying issue or configure Flake8's `ignore` or `per-file-ignores` options in a `.flake8` config file for project-wide exclusions, documenting the reason for the exclusion.","message":"Using `# noqa` comments to ignore errors on a line or file (`# flake8: noqa`) can be convenient but may hide legitimate bugs or style violations, degrading code quality over time if overused.","severity":"gotcha","affected_versions":"All"},{"fix":"Ensure that shell commands like `flake8 .` are executed in a shell environment (e.g., directly in a shell script, in a CI configuration command, or via Python's `subprocess` module if embedded within a Python script, like `subprocess.run(['flake8', '.'])`).","message":"A `SyntaxError: invalid syntax` when attempting to run `flake8 .` (or similar shell commands) directly from a Python script indicates that the command is being interpreted by the Python interpreter itself, rather than executed in a shell environment. Python treats `flake8 .` as invalid syntax.","severity":"gotcha","affected_versions":"All"},{"fix":"Ensure Flake8 is executed as a shell command. If running within a Python script, use `subprocess.run(['flake8', '.'])` or `os.system('flake8 .')`. If using a Dockerfile or CI script, execute it directly, e.g., `RUN flake8 .` or `CMD flake8 .`.","message":"The Flake8 command was invoked directly within a Python interpreter, leading to a `SyntaxError`. Flake8 is a command-line tool and should be executed as a shell command (e.g., `flake8 .` or `python -m flake8 .`), not as Python syntax.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-11T05:10:13.648Z","next_check":"2026-06-28T00:00:00.000Z","problems":[{"fix":"Install flake8 using pip: `pip install flake8` or `python -m pip install flake8`.","cause":"Flake8 is not installed in the active Python environment or its executable is not found in the system's PATH. This often happens when flake8 is installed in a different virtual environment or globally, but the current environment does not have access to it.","error":"ModuleNotFoundError: No module named 'flake8'"},{"fix":"Ensure the name is defined before its first use, or import it if it's from another module. For forward references in type hints, `from __future__ import annotations` (for Python < 3.9) or string literal type hints can be used.","cause":"The Python code attempts to use a variable, function, or class name that has not been defined or imported in the current scope. This error comes from Pyflakes, which Flake8 wraps.","error":"F821 undefined name 'name'"},{"fix":"Correct the underlying Python syntax or indentation error in the specified file and line. This is a core Python language error.","cause":"The Python code contains a fundamental syntax error or an indentation error that prevents the Python interpreter from parsing the file. Flake8 reports this error because it cannot process malformed Python code.","error":"E901 SyntaxError: invalid syntax"},{"fix":"To ignore this specific warning, add `--ignore=W503` to the `flake8` command-line arguments, or include `ignore = W503` or `extend-ignore = W503` in your `flake8` configuration file (`.flake8`, `setup.cfg`, or `tox.ini`).","cause":"Pycodestyle, a component of Flake8, flags a style violation where a line break occurs immediately before a binary operator (e.g., `+`, `-`, `*`, `/`). This rule can conflict with preferences or auto-formatters like Black.","error":"W503 line break before binary operator"},{"fix":"Use `--max-line-length` in command-line arguments (e.g., `flake8 --max-line-length=100 your_file.py`) or `max-line-length = 100` in a configuration file.","cause":"The command-line option or configuration file entry for setting the maximum line length is misspelled or incorrectly formatted, using camel case instead of hyphens.","error":"flake8: error: no such option: --maxLineLength"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":0,"quickstart_tag":"stale","pypi_latest":null,"quickstart_checks":{"last_tested":"2026-04-23","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}