mypy "Cannot find implementation or library stub" in CI
mypy needs either the module source or a type stub to analyze an import. When it can find neither - because the package is not installed for mypy, or it ships no stubs - it reports this error.
What this error means
mypy fails with "error: Cannot find implementation or library stub for module named 'X' [import-not-found]" and a hint to install the package or stubs.
python
app/client.py:3: error: Cannot find implementation or library stub for module
named "requests" [import-not-found]
app/client.py:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-importsCommon causes
The package is not installed in the mypy environment
mypy resolves imports against the environment it runs in; if the dependency is missing there, it cannot find the module.
No bundled stubs and the stub package is absent
A package without inline types needs a separate types-* stub package that has not been installed.
How to fix it
Install the package and its stubs for mypy
- Install the runtime package in the same environment mypy uses.
- Add the
types-*stub package if the library ships no inline types. - Re-run mypy.
Terminal
pip install requests types-requests
mypy app/Let mypy install missing stubs
Use mypy's install-types to fetch known stub packages automatically.
Terminal
mypy --install-types --non-interactive app/How to prevent it
- Install your full dependency set in the mypy CI environment.
- Add the relevant
types-*packages for untyped libraries. - Run mypy in the same environment that has the project dependencies.
Related guides
mypy "Skipping analyzing X: module is installed but missing stubs" in CIFix mypy "Skipping analyzing X: module is installed, but missing library stubs or py.typed marker" in CI - th…
mypy "error: Module has no attribute" in CIFix mypy "error: Module X has no attribute Y" in CI - the type checker cannot find a name on a module, from m…
Pydantic v2 "BaseSettings has been moved" in CIFix the Pydantic v1-to-v2 "BaseSettings has been moved to pydantic-settings" error in CI - settings classes m…