đź“ť Edit page
âž• Add page
Missing imports
What to do when Mypy gives an error that it cannot find types for imports
See Missing imports in the docs.
Related
- Install types cheatsheet
Refactor imports
Good
Be explicit that a module is local.
from . import foo
foo.greet()
To import an object directly:
from .foo import greet
Unfortunately, any dot imports will break unless you use this approach for your CLI:
$ python -m my_app.my_module
Bad
This code is also valid to run.
import foo
foo.greet()
But since it not clearly local, Mypy will think it is external (installed) and complain that it can’t be found.
error: Cannot find implementation or library stub for module named “foo”
You would run that as:
$ cd my_app
$ python my_module.py
Ignore
If you can’t find types for a library updating coding or installing packages, you can silence the Mypy errors.