Skip to content
Latchkey

mypy --install-types: Fetch Missing Stub Packages

mypy --install-types installs the third-party stub packages mypy reports as missing.

Rather than ignoring untyped libraries, you can install their stubs. In CI this needs an extra flag so it does not stop to ask for confirmation.

What it does

mypy --install-types reads the list of missing stub packages mypy detected (for example types-requests, types-PyYAML) and pip-installs them. By default it prompts for confirmation before installing.

Common usage

Terminal
# interactive: prompts before installing
mypy --install-types

# CI: never prompt
mypy --install-types --non-interactive src/

Options

FlagWhat it does
--install-typesInstall the missing stub packages mypy found
--non-interactiveDo not prompt; required to pair with --install-types in CI
--ignore-missing-importsAlternative: suppress rather than install

In CI

Always pair --install-types with --non-interactive in a pipeline; the bare flag waits for a yes/no answer on stdin and hangs the job. Note that --install-types runs mypy twice (once to discover missing stubs, once to check with them), so a single invocation re-runs the analysis.

Common errors in CI

Without --non-interactive the job blocks at "Install? [yN]" until it times out. If installation succeeds but stubs are still not found, the stub package may need to be in the same environment mypy runs in; install it into the active venv. "error: Cannot find implementation or library stub" persists when no stub package exists for that library.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →