See Missing imports in the docs.

Refactor imports


Be explicit that a module is local.

from . import foo


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


This code is also valid to run.

import foo


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


If you can’t find types for a library updating coding or installing packages, you can silence the Mypy errors.