mypy 给出错误 即使添加 MYPYPATH 后也无法找到名为 math_func 的模块的实现或库存根
我在包 'code' 下有两个模块。
math_func.py 中的第一个模块
是 main.py。
我正在 main.py 中导入 math_func.py。早些时候,当我运行 mypy ot 时,出现错误
'''无法找到名为“math_func”的模块的实现或库存根''',
但在阅读 mypy 文档后,我使用命令
(project_2) p0p029i@m-c02dt1k2md6n enviroment_2 % export 添加了路径 MYPYPATH MYPYPATH=/Users/p0p029i/Desktop/enviroment_2
i我再次遇到同样的错误。附上截图供参考。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
math_func
不是顶级模块,因为code/
下有__init__.py
。因此,您应该改为编写
import code.math_func
或删除code/__init__.py
。将
environment_2
添加到MYPYPATH
并不能解决问题,因为它仍然不允许 mypy 发现math_func
作为顶级模块。为了更好地理解它,请考虑以下导入之间的差异:
math_func
is not a top-level module, as you have__init__.py
undercode/
.So you should write
import code.math_func
instead OR removecode/__init__.py
.Adding
environment_2
toMYPYPATH
does not solve it because it still doesn't allow mypy to discovermath_func
as a top-level module.To have a better understanding of it, consider the difference between the following imports: