Installation
Mypy requires Python 3.10 or later to run. You can install it using pip, install from source, or use alternative installation methods.
Requirements
Mypy requires Python 3.10 or later to run. The type checker itself needs this version, but you can configure mypy to check code targeting older Python versions.
Installing with pip
The easiest way to install mypy is using pip:
python3 -m pip install -U mypy
This installs the latest stable version of mypy from PyPI.
Verify your Python version
Make sure you have Python 3.10 or later installed: You should see output like Python 3.10.0 or higher.
Install mypy
Install mypy using pip: python3 -m pip install -U mypy
The -U flag ensures you get the latest version.
Verify installation
Check that mypy is installed correctly: You should see output like mypy 1.x.x (compiled: yes).
Installing from source
If you want to run the latest development version, install directly from the GitHub repository:
python3 -m pip install -U git+https://github.com/python/mypy.git
The development version may contain bugs or incomplete features. Use the stable release for production work.
Installing without compilation
By default, mypy is installed as a compiled package using mypyc , which makes it approximately 4x faster. If you need an interpreted version instead:
python3 -m pip install --no-binary mypy -U mypy
The compiled version is recommended for most users. Only use the interpreted version if you’re debugging mypy itself or have specific compatibility requirements.
Optional dependencies
Mypy supports several optional features that require additional packages:
Daemon mode
HTML/XML reports
Faster cache
All extras
python3 -m pip install mypy[dmypy]
Optional dependencies explained
dmypy - Installs psutil for daemon mode, which provides much faster incremental updates
reports - Installs lxml for generating HTML and XML coverage reports
faster-cache - Installs orjson for faster cache serialization
install-types - Installs pip for the --install-types feature (usually already available)
IDE integrations
Mypy can be integrated into popular editors and IDEs:
Emacs Use Flycheck for Emacs integration.
VS Code setup
For VS Code, mypy support is built in:
Install the Python extension
Install the official Python extension from Microsoft.
Enable mypy
Add to your .vscode/settings.json: {
"python.linting.mypyEnabled" : true ,
"python.linting.enabled" : true
}
Vim setup
Using Syntastic
Using ALE
Add to your ~/.vimrc: let g:syntastic_python_checkers = [ 'mypy' ]
ALE enables mypy by default when it’s installed. To explicitly enable it: " In ~/vim/ftplugin/python.vim
let b:ale_linters = [ 'mypy' ]
Pre-commit hook
Integrate mypy with pre-commit to check code before commits:
repos :
- repo : https://github.com/pre-commit/mirrors-mypy
rev : v1.8.0
hooks :
- id : mypy
By default, this limits mypy’s ability to analyze third-party dependencies. See the pre-commit mirrors-mypy documentation for workarounds.
Verifying installation
Once installed, verify mypy works correctly:
Check version
Expected output: mypy 1.8.0 (compiled: yes)
Create a test file
Create a file called test.py: def greeting ( name : str ) -> str :
return "Hello " + name
greeting( 123 ) # This should produce an error
Run mypy
Expected output: test.py:4: error: Argument 1 to "greeting" has incompatible type "int"; expected "str" [arg-type]
Found 1 error in 1 file (checked 1 source file)
If you see the error message above, congratulations! Mypy is working correctly.
Troubleshooting
Command not found
If you get mypy: command not found, the installation directory may not be in your PATH:
# Try using the module form instead
python3 -m mypy test.py
# Or add pip's bin directory to your PATH
export PATH = " $HOME /.local/bin: $PATH "
Python version mismatch
If you see errors about Python version requirements:
Check Python version
Upgrade Python
Import errors
If you see import errors when running mypy, ensure the packages are installed in the same environment:
# Check which Python mypy is using
which mypy
python3 -c "import sys; print(sys.executable)"
# If they differ, reinstall mypy in the correct environment
python3 -m pip install --force-reinstall mypy
Next steps
Now that mypy is installed, you’re ready to start type checking! Head over to the quickstart guide to learn how to use mypy on your code.