Skip to main content

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.
1

Verify your Python version

Make sure you have Python 3.10 or later installed:
python3 --version
You should see output like Python 3.10.0 or higher.
2

Install mypy

Install mypy using pip:
python3 -m pip install -U mypy
The -U flag ensures you get the latest version.
3

Verify installation

Check that mypy is installed correctly:
mypy --version
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:
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:

VS Code

VS Code provides basic integration with mypy out of the box.

PyCharm

Install the mypy plugin for PyCharm.

Vim

Use Syntastic or ALE for Vim integration.

Emacs

Use Flycheck for Emacs integration.

VS Code setup

For VS Code, mypy support is built in:
1

Install the Python extension

Install the official Python extension from Microsoft.
2

Enable mypy

Add to your .vscode/settings.json:
{
  "python.linting.mypyEnabled": true,
  "python.linting.enabled": true
}

Vim setup

Add to your ~/.vimrc:
let g:syntastic_python_checkers=['mypy']

Pre-commit hook

Integrate mypy with pre-commit to check code before commits:
.pre-commit-config.yaml
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:
1

Check version

mypy --version
Expected output:
mypy 1.8.0 (compiled: yes)
2

Create a test file

Create a file called test.py:
test.py
def greeting(name: str) -> str:
    return "Hello " + name

greeting(123)  # This should produce an error
3

Run mypy

mypy test.py
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:
python3 --version

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.

Build docs developers (and LLMs) love