pycodestyle Error Codes Explained: E1 to E9 and W1 to W6

Every warning from pycodestyle starts with a code such as E302 or W291. The same codes appear in flake8, which runs pycodestyle, and in ruff, which reimplements them. This page explains each family, with the fix for the codes you will meet most often.
Reading a warning
pycodestyle prints one line per problem: file, line, column, code and message.
optparse.py:69:11: E401 multiple imports on one line
optparse.py:77:1: E302 expected 2 blank lines, found 1
The tool's documentation is clear about its limits: it "does not enforce every single rule of PEP 8". Naming conventions and docstrings are out of its scope. In its default configuration it skips the checks listed above, "because they are not rules unanimously accepted, and PEP 8 does not enforce them". Passing --ignore replaces that default list rather than adding to it, a common surprise; flake8's --extend-ignore exists to add codes instead.
E1: indentation
| Code | Meaning and fix |
|---|---|
E101 | Indentation mixes tabs and spaces. Convert the file to spaces. |
E111, E114 | Indentation is not a multiple of four (E114 for a comment line). |
E112, E115 | Expected an indented block (after a line ending in a colon). |
E113, E116 | Unexpected indentation. |
E117 | Over-indented: more than one level at once. |
E121 to E131 | Continuation lines: under- or over-indented, closing bracket misplaced, or a continuation that looks like the next logical line. E121, E123 and E126 are ignored by default. |
See indentation and line length for the underlying rules.
E2: whitespace
| Code | Meaning and fix |
|---|---|
E201, E202 | Space just after an opening or before a closing bracket: f( x ) → f(x). |
E203 | Space before a comma, semicolon or colon. Often disabled with black, which puts spaces around colons in complex slices as PEP 8 allows. |
E211 | Space before the parenthesis of a call or the bracket of an index: f (x). |
E221–E224 | Several spaces, or a tab, before or after an operator, often from aligning assignments. |
E225 | Missing whitespace around an operator that needs it: x=1, if a==b. |
E226–E228 | Missing whitespace around arithmetic (E226, ignored by default), bitwise or shift (E227) and modulo (E228) operators. |
E231 | Missing whitespace after a comma, semicolon or colon: [1,2]. |
E241, E242 | Several spaces or a tab after a comma (ignored by default). |
E251, E252 | Spaces around = in a keyword argument or plain default (E251), or missing around an annotated default (E252). |
E261, E262 | Inline comment: fewer than two spaces before it, or not starting with # . |
E265, E266 | Block comment not starting with # , or starting with ##. |
E271–E275 | Several spaces or a tab around a keyword, or no space after one: if(x). |
E3: blank lines
| Code | Meaning and fix |
|---|---|
E301 | Expected 1 blank line before a method. |
E302 | Expected 2 blank lines before a top-level function or class. |
E303 | Too many blank lines: more than two, or two inside a function or class. |
E304 | Blank line between a decorator and its function. |
E305 | Expected 2 blank lines after a function or class, before top-level code. |
E306 | Expected 1 blank line before a nested definition. |
E4: imports
E401: several modules imported on one line (import os, sys). E402: a module-level import that comes after other code. A docstring, comments, dunder assignments such as __all__ and conditional blocks are allowed before imports. Grouping and ordering imports is not checked by pycodestyle; tools such as isort or ruff handle it.
E5: line length
E501: line too long, with the length and the limit in the message, for example "(84 > 79 characters)". The limit is set with --max-line-length. Long URLs alone in a comment are tolerated, as is a long first line starting with #!. E502 flags a backslash that is redundant because the line is already inside brackets.
E7: statements
| Code | Meaning and fix |
|---|---|
E701, E702 | Several statements on one line, after a colon (if x: y()) or separated by semicolons. |
E703 | Statement ends with a semicolon. |
E704 | Function body on the same line as def (ignored by default). |
E711, E712 | Comparison to None, True or False with == or !=. Use is, is not, or plain truthiness. |
E713, E714 | not x in y and not x is y: write x not in y and x is not y. |
E721 | Comparing types directly; use isinstance(), or is for exact type checks. |
E722 | Bare except:; name the exception, or use except Exception:. |
E731 | A lambda assigned to a name; use def. |
E741–E743 | Ambiguous names l, O or I for a variable, class or function. |
Most of these follow the programming recommendations at the end of PEP 8.
E9: runtime
E901: the file could not be tokenized, usually a syntax or indentation error. E902: the file could not be read. Fix these first: other checks stop when the tokenizer fails.
W1, W2, W3: indentation and whitespace warnings
W191: indentation contains tabs.W291: trailing whitespace.W293: whitespace on a blank line.W292: no newline at the end of the file.W391: blank line at the end of the file.
W5: line breaks
W503 and W504 flag a line break before and after a binary operator. They contradict each other and both are ignored by default; PEP 8 suggests breaking before operators in new code. W505 limits the length of docstrings and comments when --max-doc-length is set.
W6: deprecation
W605: invalid escape sequence, such as "\d" in a regular expression written as a normal string. Python currently treats it as a backslash followed by the character, but emits a warning, and the documentation says it will eventually become an error. Use a raw string: r"\d+".
Selecting, ignoring and silencing
pycodestyle --select=E,W --max-line-length=88 src/
pycodestyle --ignore=E203,W503 src/
flake8 --extend-ignore=E203 src/
Configuration usually lives in setup.cfg or tox.ini under [pycodestyle], or [flake8] for flake8, which also reads a .flake8 file. For one line, add # noqa: E501; pycodestyle documents which of its checks honour noqa. Our guide to checking style locally shows complete configurations for pycodestyle, flake8 and ruff.
The checker on our home page implements most of the codes on this page in the browser, including all of E1 except the continuation-line checks, E2, E3, E4, E501, E7, W191, W291 to W293, W391 and W605.
Sources
- pycodestyle documentation, "Error codes", disclaimer and configuration (version 2.15).
- PEP 8 – Style Guide for Python Code.
- Python Language Reference, escape sequences (invalid escape sequences).
- flake8 documentation, options
--extend-ignoreand configuration files.
Linters & formattersCheck style locally
Install a checker in a virtual environment, run it on your project, configure it once and let it fix what it can: pycodestyle, flake8 and ruff step by step.
PEP 8, section by sectionWhitespace and blank lines
Spaces around operators and commas, none inside brackets, two blank lines between functions: the rules, the warnings, and the one place the checker disagrees with PEP 8.
Linters & formattersflake8 and pylint compared
Same file, two linters: flake8 found nothing, pylint found six things. What each tool checks, how to configure it and when to use both.