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
# interactive: prompts before installing
mypy --install-types
# CI: never prompt
mypy --install-types --non-interactive src/Options
| Flag | What it does |
|---|---|
| --install-types | Install the missing stub packages mypy found |
| --non-interactive | Do not prompt; required to pair with --install-types in CI |
| --ignore-missing-imports | Alternative: 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.