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 pylintVerified import paths — ran on the pinned version, not inferred.
The most common way to use Pylint is via the command line, simply by pointing it to a Python file, module, or package. For integration into tools or CI/CD pipelines, Pylint can also be invoked programmatically using `pylint.lint.Run`, allowing for custom reporters and output handling. The quickstart demonstrates both methods.
Replace `from pylint import __pkginfo__` with `from importlib import metadata; metadata.metadata('pylint')`.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.
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.
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.
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.
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.
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).
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.
Add a triple-quoted string (docstring) at the very top of your Python file, after the shebang but before any code or imports. ```python """A brief description of what this module does.""" # Your code starts here import os ```
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.
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`.
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.
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>`.