简体   繁体   中英

Mypy, python paths, “cannot find implementation or library stub”

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.

try

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM