mypy giving error Cannot find implementation or library stub for module named math_func even after adding MYPYPATH

Viewed 862

i have two modules under package 'code' .

First module in math_func.py

another one is main.py.

I am importing math_func.py in main.py. Earlier when i was running mypy ot was giving error

'''Cannot find implementation or library stub for module named "math_func"'''

but after reading mypy docs i added path MYPYPATH using command

(project_2) p0p029i@m-c02dt1k2md6n enviroment_2 % export MYPYPATH=/Users/p0p029i/Desktop/enviroment_2

i am again getting the same error. Attached screenshot for reference.

main.py

math_func.py

1 Answers

math_func is not a top-level module, as you have __init__.py under code/. So you should write import code.math_func instead OR remove code/__init__.py.

Adding environment_2 to MYPYPATH does not solve it because it still doesn't allow mypy to discover math_func as a top-level module.

To have a better understanding of it, consider the difference between the following imports:

import .math_func      # relative import
import math_func       # look for a top-level module "math_func"
import code.math_func  # look for a top-level module "code" that has a submodule math_func underneath
import re              # look for a top-level module "re"
Related