Install & Compatibility
Where this runs
tested against v1.7.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.054s · 65.7MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 1.5s · import 0.050s · 18MB
65MB installed
● package 65MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Checker
✓ from pep8 import Checker
✗ from pycodestyle import Checker
The `pep8.Checker` class exists for direct programmatic use with the legacy `pep8` package. For new projects or updated code, use `from pycodestyle import Checker` instead.
The `pep8` package is primarily used via its command-line interface. For programmatic checks, you can import `Checker` and instantiate it with a file path. The `check_all()` method runs checks and prints errors directly to stdout, returning the total count of errors found. For modern usage, consider the `pycodestyle` package.
import os
# Create a dummy Python file to check
with open('example.py', 'w') as f:
f.write('def my_function(a,b):\n return a+ b\n')
# Command-line usage (typical)
# import subprocess
# subprocess.run(['pep8', 'example.py'])
# Programmatic usage of the legacy pep8 package
from pep8 import Checker
# You can pass a filename or a file-like object
checker = Checker('example.py')
errors = checker.check_all()
print(f"Found {errors} style errors.")
if errors > 0:
print("Note: The pep8 package prints errors directly to stdout during check_all().")
# Cleanup (optional)
os.remove('example.py')
pep8 --version
Debug
Known issues
breakingThe `pep8` package has been renamed to `pycodestyle`. While `pep8` (version 1.7.1) is still available on PyPI, it is no longer actively maintained under this name. New features and bug fixes are exclusively released in `pycodestyle`.fixMigrate to `pycodestyle`. Uninstall `pep8` and install `pycodestyle`: `pip uninstall pep8 && pip install pycodestyle`. Update import statements from `pep8` to `pycodestyle` (e.g., `from pep8 import Checker` becomes `from pycodestyle import Checker`).
affects: 1.7.0 and older
gotchaThe `pep8` command-line tool and its programmatic interface directly print style errors to standard output. This can make it challenging to capture and process errors programmatically without redirecting output or using `pycodestyle`'s more flexible API.fixFor command-line usage, redirect output to a file if you need to capture it. For programmatic integration, consider using the `pycodestyle` library, which offers more options for handling reported errors, or capturing `stdout` if sticking with `pep8`.
affects: All versions of pep8 (1.0 - 1.7.1)
gotchaMixing tabs and spaces for indentation is a common PEP 8 violation that often leads to hard-to-debug `IndentationError` in Python 3. PEP 8 strongly recommends using 4 spaces per indentation level.fixConfigure your editor to use 4 spaces for indentation and ensure 'tabs to spaces' conversion is enabled. Use tools like `autopep8` or `black` for automatic formatting.
affects: All Python versions, checked by pep8 1.0 - 1.7.1
Errors
Common errors & fixes
pep8: command not found
The `pep8` executable is not found in the system's PATH, or the package was installed in a virtual environment that is not activated, or the user is trying to run the deprecated command-line tool after the package was renamed to `pycodestyle`.
fixEnsure the directory containing the `pep8` (or `pycodestyle`) executable is in your system's PATH, or use `python -m pep8` (which still works for the installed `pycodestyle` package), or preferably install `pycodestyle` directly and use the `pycodestyle` command instead.
ModuleNotFoundError: No module named 'pep8'
The `pep8` Python package is not installed in the active Python environment, or the user is attempting to `import pep8` when the package has been renamed and should be imported as `pycodestyle`.
fixInstall the package using `pip install pep8` (which will actually install `pycodestyle` and provide compatibility) or preferably `pip install pycodestyle`. To import the functionality in Python code, use `import pycodestyle`.
E501 line too long
A line of code exceeds the maximum character limit (default 79 characters) defined by PEP 8.
fixRefactor the long line by breaking expressions with parentheses, splitting string literals, or separating multiple assignments. While not strictly PEP 8 compliant for all cases, the line length limit can sometimes be configured in wrapper tools like `flake8` to a higher value.
E401 multiple imports on one line
Multiple modules are imported on a single line, which violates the PEP 8 style guide that recommends each import be on its own line.
fixRewrite the import statement to place each imported module on a separate line. For example, change `import os, sys` to `import os` and `import sys`.
Upgrade
Version history
1.7.1latest on PyPI · released Oct 24, 2017
Audit
Dependencies
No dependency data recorded yet.