Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Pytype is primarily a command-line tool. To quickly get started, run `pytype` followed by the file or directory you wish to analyze. For project-level configuration, use a `pyproject.toml` file to specify inputs and settings.
# To check a single file or directory:
# pytype my_module.py
# pytype my_package/
# For package-wide configuration using pyproject.toml:
# 1. Create a pyproject.toml in your project root with the following:
# [tool.pytype]
# inputs = ['your_package_name']
# 2. Then run pytype without arguments:
# pytype
# Example Python file (example.py):
def greet(name):
return "Hello, " + name
def add(a, b):
return a + b
# Run pytype on this file from your terminal:
# pytype example.py
# Expected output for add function (e.g., if you call add(1, '2')):
# File "example.py", line 5, in add: unsupported operand type(s) for +: 'int' and 'str' [unsupported-operands]
pytype --version
Debug
Known issues
breakingPytype is in maintenance mode; Google has discontinued active development, and Python 3.12 is the last supported version. No new features will be added, only bugfixes. Users are encouraged to explore alternative type checkers like Mypy, Pyright, ty, or Pyrefly.fixConsider migrating to actively developed type checkers if you need support for newer Python versions or actively evolving typing features.
affects: All versions beyond Python 3.12 runtime environment.
gotchaPytype's default behavior is lenient compared to other type checkers like Mypy. It allows operations that succeed at runtime and don't contradict annotations, which might lead to different results, particularly with container types or `Optional` handling.fixBe aware of Pytype's leniency. If stricter checking is desired, review Pytype's error classes and configuration options, or consider a different type checker.
affects: All
gotchaFor silencing specific errors, use `pytype: disable=error-class` on the line or block, or `type: ignore`. Disabling errors for an entire file can be done by placing a disable directive on its own line at the start of the file.fixUse inline directives like `# pytype: disable=attribute-error` or `# type: ignore` for specific suppression. Consult the error classes documentation for precise error names.
affects: All
gotchaPerformance can degrade significantly on very large Python files (anecdotally, over ~1500 lines). Extensive inference on complex, unannotated code can be slow.fixSplit large files into smaller modules. Add explicit type annotations to function parameters and return types. Simplify complex variable initializations or union types.
affects: All
gotchaSome experimental features, such as `...` as a top-level annotation for 'inferred type', are unique to Pytype and not supported by other type checkers (e.g., Mypy, Pyright). Using these can lead to errors when analyzing code with other tools.fixAvoid experimental Pytype-specific annotations in code intended for wider compatibility or analysis by other type checkers.
affects: All
gotchaPytype is primarily developed and tested on Linux. While it supports macOS (10.7+ and Xcode 8+), Windows support typically requires the Windows Subsystem for Linux (WSL).fixFor Windows users, it is recommended to run Pytype within a WSL environment.
affects: All
Errors
Common errors & fixes
pytype: command not found
The `pytype` executable is not in your system's PATH, meaning it was either not installed or its installation directory is not recognized.
fixInstall `pytype` using pip and ensure your environment's script directory is in your PATH, or run it via `python -m pytype your_file.py`.
`pip install pytype`
pytype: error: Python 3.13 is not supported. The last supported version is 3.12.
Pytype officially supports Python versions up to 3.12; running it with a newer Python interpreter will result in this error.
fixUse a Python environment with version 3.12 or earlier to run `pytype`.
`python3.12 -m venv pytype_env`
`source pytype_env/bin/activate`
`pip install pytype`
`pytype your_file.py`
ERROR: Could not find a version that satisfies the requirement pytype
This error typically occurs when trying to install `pytype` with an unsupported Python version for which no pre-built wheels are available on PyPI, or due to network issues.
fixEnsure you are using a supported Python version (3.6-3.12) to install `pytype`, or check your internet connection and package name.
`python3.12 -m pip install pytype`
file.py:1: import-error: No module named 'your_module'
Pytype cannot locate an imported module, often because the module is not installed in the Python environment `pytype` is analyzing, or the `pythonpath` is not correctly configured.
fixEnsure the module is installed in the Python environment `pytype` uses, or add the module's path to `pytype`'s configuration using the `--pythonpath` flag or in your `.pytypecfg`.
`pip install your_module`
`pytype --pythonpath=/path/to/modules your_file.py`
Python 3.13 is not supported by Pytype
Pytype's development is in maintenance mode and officially supports Python versions up to 3.12.
fixUse a Python environment with a version between 3.6 and 3.12. If using Python 3.13+, consider using a tool like `pyenv` to switch to a supported version, or use `pytype --python-version=3.12` as a workaround.
Upgrade
Version history
2024.10.11latest on PyPI · released Oct 11, 2024
Audit
Dependencies
wheeloptionalRequired for installation, especially outside a virtual environment or from source.
setuptoolsoptionalRequired for installation, especially outside a virtual environment or from source.
build-essentialoptionalRequired for installation on Linux-based systems.
python3-devoptionalRequired for installation on Linux-based systems.
libpython3-devoptionalRequired for installation on Linux-based systems.