Pylint
raw JSON → 4.0.5 verified Tue May 12 auth: no python install: verified quickstart: stale
Pylint is a widely used static code analyzer for Python. It inspects source code without execution to detect programming errors, enforce coding standards (like PEP 8), identify code smells, and suggest refactorings. It provides a detailed report and a code quality score. Pylint maintains an active development status with regular releases, including minor versions for new checks and bug fixes, and major versions that may introduce breaking changes to options or output formats.
pip install pylint Common errors
error missing-module-docstring ↓
cause Pylint requires Python modules to have a docstring at the beginning of the file to explain the module's purpose, as per coding style conventions like PEP 257.
fix
Add a triple-quoted string (docstring) at the very top of your Python file, after the shebang but before any code or imports.
"""A brief description of what this module does."""
# Your code starts here
import os error pylint Unable to import ↓
cause Pylint cannot find the specified module because it's not in Python's `sys.path`, often due to an incorrect virtual environment, a custom module not being on the path, or a misspelled import statement.
fix
Ensure the module is installed in the correct environment (e.g.,
pip install your-module). If it's a local module, ensure its containing directory is on the PYTHONPATH or configure Pylint's init-hook in .pylintrc to add the path. For Visual Studio Code, select the correct Python interpreter for your project. error pylint no-name-in-module (E0611) ↓
cause Pylint reports this error when a specific name (function, class, variable) imported from a module cannot be found within that module. This can happen if the name is misspelled, not actually exported by the module, or if Pylint has trouble analyzing the module due to complex imports or dynamic code.
fix
Double-check the spelling of the imported name. Verify that the name is indeed available in the module you are importing from. If it's a dynamic import or Pylint's analysis is failing, you might need to add
ignored-modules or generated-members to your .pylintrc or use an inline disable comment # pylint: disable=no-name-in-module. error pylint unused-import (W0611) ↓
cause This warning occurs when a module or a specific name imported from a module is not used anywhere in the code that follows the import statement, indicating potentially unnecessary code.
fix
Remove the unused import statement. If the import is necessary for some reason (e.g., for side effects or for a
__init__.py exposing submodules), you can disable the warning for that specific line or file using # pylint: disable=unused-import or configure good-names for specific cases. error pylint: command not found ↓
cause The 'pylint' command is not recognized by your system's shell because the directory where Pylint is installed is not included in your system's PATH environment variable, or Pylint was not installed correctly.
fix
Ensure Pylint is installed in your current Python environment (
pip install pylint). If installed, locate the Pylint executable (often in Scripts/ on Windows or bin/ in a Unix-like environment within your Python installation or virtual environment) and add that directory to your system's PATH. Alternatively, run Pylint using python -m pylint [options] <files>. Warnings
breaking Pylint 4.x removes direct access to package metadata via `pylint.__pkginfo__`. Users should migrate to `importlib.metadata` for retrieving package information. ↓
fix Replace `from pylint import __pkginfo__` with `from importlib import metadata; metadata.metadata('pylint')`.
breaking Pylint 4.x officially drops support for *launching* Pylint with Python 3.9. While it can still *lint* code written for Python 3.9 (or older) using `--py-version=3.9`, the environment running Pylint itself must be Python 3.10.0 or newer. ↓
fix Ensure that the Python interpreter used to install and run Pylint is 3.10.0 or newer. If linting older Python code, use the `--py-version` flag.
breaking In Pylint 3.x, the behavior of enabling or disabling individual messages changed. The order of `--enable` or `--disable` flags (or their counterparts in configuration files) now strictly dictates their application, meaning later options can override earlier ones. ↓
fix Review configuration files and command-line arguments to ensure the intended message enabling/disabling order is maintained. Avoid redundant or conflicting `enable=all`/`disable=all` with specific message controls.
gotcha Pylint's default configuration can be very verbose, especially on legacy or less-PEP 8 compliant projects. This often leads to an overwhelming number of messages upon first run. ↓
fix During initial adoption, start with `--errors-only` or disable convention/refactor messages (e.g., `--disable=C,R`) and progressively re-enable checks as code quality improves. Generate a `.pylintrc` file (`pylint --generate-rcfile > .pylintrc`) for granular control over messages and checkers.
gotcha The `invalid-name` message often triggers due to Pylint's default expectation of `UPPERCASE` for module-level constants, which might conflict with project-specific naming conventions. ↓
fix Customize the regular expressions for naming conventions in your `.pylintrc` file. For instance, modify `--const-rgx` or `--variable-rgx` to match your project's style.
gotcha Pylint relies on Python's module resolution mechanism. Incorrect `PYTHONPATH` settings or running Pylint from an unexpected working directory can lead to it analyzing the wrong module version or failing to import modules, resulting in `import-error` messages. ↓
fix Always run Pylint from the project root or a directory where Python can correctly resolve your modules. Verify your `PYTHONPATH` environment variable if encountering import issues.
breaking The Python script being linted contains a fundamental `SyntaxError`, preventing Pylint from analyzing the code. Pylint cannot process files that are not valid Python. ↓
fix Before running Pylint, ensure that the target Python script is free of basic syntax errors. Correct the `SyntaxError` in the script as indicated by the Python interpreter (e.g., unclosed string literals, unmatched parentheses/brackets).
gotcha The script executed as part of the test setup contains a fundamental Python syntax error, preventing its successful execution. This is independent of Pylint's behavior or specific version. ↓
fix Correct the syntax error in the relevant Python script (e.g., ensure all string literals are properly terminated) before attempting to run the test or Pylint.
Install
pip install pylint[spelling] Install compatibility verified last tested: 2026-05-12
python os / libc variant status wheel install import disk
3.10 alpine (musl) pylint wheel - 0.41s 26.8M
3.10 alpine (musl) spelling wheel - 0.41s 27.2M
3.10 alpine (musl) pylint - - 0.42s 26.8M
3.10 alpine (musl) spelling - - 0.44s 27.2M
3.10 slim (glibc) pylint wheel 2.6s 0.29s 27M
3.10 slim (glibc) spelling wheel 2.6s 0.29s 28M
3.10 slim (glibc) pylint - - 0.30s 27M
3.10 slim (glibc) spelling - - 0.30s 28M
3.11 alpine (musl) pylint wheel - 0.58s 30.0M
3.11 alpine (musl) spelling wheel - 0.58s 30.4M
3.11 alpine (musl) pylint - - 0.64s 30.0M
3.11 alpine (musl) spelling - - 0.96s 30.4M
3.11 slim (glibc) pylint wheel 2.6s 0.53s 31M
3.11 slim (glibc) spelling wheel 2.8s 0.52s 31M
3.11 slim (glibc) pylint - - 0.49s 30M
3.11 slim (glibc) spelling - - 0.50s 31M
3.12 alpine (musl) pylint wheel - 0.55s 21.5M
3.12 alpine (musl) spelling wheel - 0.51s 21.9M
3.12 alpine (musl) pylint - - 0.59s 21.5M
3.12 alpine (musl) spelling - - 0.62s 21.9M
3.12 slim (glibc) pylint wheel 2.6s 0.55s 22M
3.12 slim (glibc) spelling wheel 2.5s 0.57s 22M
3.12 slim (glibc) pylint - - 0.54s 22M
3.12 slim (glibc) spelling - - 0.52s 22M
3.13 alpine (musl) pylint wheel - 0.52s 21.3M
3.13 alpine (musl) spelling wheel - 0.50s 21.7M
3.13 alpine (musl) pylint - - 0.54s 21.1M
3.13 alpine (musl) spelling - - 0.53s 21.6M
3.13 slim (glibc) pylint wheel 2.4s 0.50s 22M
3.13 slim (glibc) spelling wheel 2.6s 0.50s 22M
3.13 slim (glibc) pylint - - 0.53s 22M
3.13 slim (glibc) spelling - - 0.55s 22M
3.9 alpine (musl) pylint wheel - 0.53s 26.6M
3.9 alpine (musl) spelling wheel - 0.53s 26.9M
3.9 alpine (musl) pylint - - 0.53s 26.5M
3.9 alpine (musl) spelling - - 0.54s 26.9M
3.9 slim (glibc) pylint wheel 3.2s 0.52s 27M
3.9 slim (glibc) spelling wheel 3.3s 0.50s 27M
3.9 slim (glibc) pylint - - 0.48s 27M
3.9 slim (glibc) spelling - - 0.45s 27M
Imports
- Run
from pylint.lint import Run - TextReporter
from pylint.reporters.text import TextReporter
Quickstart stale last tested: 2026-04-24
import os
import io
from pylint.lint import Run
from pylint.reporters.text import TextReporter
# Create a dummy Python file for linting
with open('my_module.py', 'w') as f:
f.write('"""A simple module."""
MY_CONSTANT = 10
def my_function(arg1, arg2): # arg2 is unused
return arg1 + MY_CONSTANT
')
# --- Command Line Usage ---
print("\n--- Command Line Pylint ---")
os.system('pylint my_module.py')
# --- Programmatic Usage ---
print("\n--- Programmatic Pylint ---")
# Capture output to a string buffer
pylint_output = io.StringIO()
reporter = TextReporter(pylint_output)
# Run Pylint on the module, disabling reports for cleaner output
# do_exit=False prevents sys.exit() on linting issues
Run(['my_module.py', '--disable=C0114,C0116,R0903', '--reports=no'], reporter=reporter, do_exit=False)
print(pylint_output.getvalue())
# Clean up the dummy file
os.remove('my_module.py')