Using PEP 561 compatible packages with mypy
Generally, you do not need to do anything to use installed packages thatsupport typing for the Python executable used to run mypy. Note that mostpackages do not support typing. Packages that do support typing should beautomatically picked up by mypy and used for type checking.
By default, mypy searches for packages installed for the Python executablerunning mypy. It is highly unlikely you want this situation if you haveinstalled typed packages in another Python’s package directory.
Generally, you can use the —python-version
flag and mypy will try to findthe correct package directory. If that fails, you can use the—python-executable
flag to point to the exact executable, and mypy willfind packages installed for that Python executable.
Note that mypy does not support some more advanced import features, such as zipimports and custom import hooks.
If you do not want to use typed packages, use the —no-site-packages
flagto disable searching.
Note that stub-only packages (defined in PEP 561: Stub-only Packages) cannot be used with MYPYPATH
. If you want mypyto find the package, it must be installed. For a package foo
, the name ofthe stub-only package (foo-stubs
) is not a legal package name, so mypywill not find it, unless it is installed.