When you run type checks with Mypy, you might get an error that types are missing for your installed 3rd-party packages.

So run a command below to install the missing types. If you canโ€™t find appropriate types, see other pages in this guide to make stubs or ignore that package for typechecks.

See typeshed README for more info.

Install using Mypy

Interactive

$ mypy --install-types

Then you have to enter y and press Enter.

Sample console output:

Installing missing stub packages:
.../python3 -m pip install types-setuptools

Install? [yN] 

Non-interactive

Or simply do this:

$ mypy --install-types --non-interactive

Install using pip

If type stubs exist for a particular package, you can install them.

See types-requests on PyPI for this example.

Install using CLI

$ pip install types-requests

Based on:

Library stubs not installed for "requests" (or incompatible with Python 3.9)
...:13: note: Hint: "python3 -m pip install types-requests"
...:13: note: (or run "mypy --install-types" to install all missing stub packages)
...:13: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

Install using requirements file

After you know what types you need, then you should switch to this approach with name added to your requirements-dev.txt file. Then everytime someone sets up your project on their machine, it will include types.

  1. Set up the file with content like:
     types-requests
    
  2. Install from it:
     $ pip install -r requirements-dev.txt