Mypy, python paths, "cannot find implementation or library stub"

Viewed 3211

I'm trying to use mypy with a package that I've written, but it can't find my stub file.

I have a workspace which looks like this:

/common

/other_dir

/another_dir

I have used a script to add all of these directories to my sys.path.

Inside each directory is a src/ directory, which contains python packages, and is itself a top-level package (has an init.py).

in /common/src/test1 I have a module called components.py, and I've written another file next to it, components.pyi.

This should work as the stub file for components.py.

In /another/src/example.py, I import like this:

from common.src.test1.components.py import x

x is detected and I can use it, but when I run mypy ./another/src/example.py, it says 'Cannot find implementation or library stub for module named 'common.src.test1.components'.

It would be great if anyone who has experience with mypy could help with this.

Many thanks.

1 Answers

try

from common.src.test1.components import x # type: ignore

Related