[英]mypypath: Cannot find module named 'tzwhere'
I am learning mypy, and the first error I got is cannot find module
. 我正在学习mypy,我遇到的第一个错误是
cannot find module
。
My file is: 我的档案是:
from tzwhere import tzwhere
tzw = tzwhere.tzwhere()
print(tzw)
It is runnable by python because tzwhere
package is installed. 它可以由python运行,因为已安装
tzwhere
软件包。 But when I run it through mypy I get this: 但是当我通过mypy运行它时,我得到了:
mypy mp.py
mp.py:1: error: Cannot find module named 'tzwhere'
mp.py:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help)
How do I make it say No library stub file for module 'tzwhere'
and deal with stub files instead of Cannot find module
? 如何使
No library stub file for module 'tzwhere'
并处理存根文件而Cannot find module
?
In order for mypy (and other PEP 484 compliant tools) to understand how to type a given module, it must be able to find stubs for that module somewhere. 为了使mypy(和其他符合PEP 484的工具)了解如何键入给定的模块,它必须能够在某个地方找到该模块的存根。
Mypy (if we simplify slightly) checks essentially two different places for stubs: Mypy(如果我们稍作简化的话)本质上检查存根的两个不同位置:
Unfortunately, it seems that tzwhere is doing neither of these things: I can't find it on typeshed; 不幸的是,看来tzwhere并没有做这两种事情:我在排版时找不到它; it doesn't appear to be bundling types.
它似乎不是捆绑类型。 As a result, mypy will not be able to accurately type check code using tzwhere.
结果,mypy将无法使用tzwhere准确键入检查代码。
You have three main options: 您有三个主要选择:
# type: ignore
annotation to the import. # type: ignore
抑制错误消息# type: ignore
对导入的注释。 Note that this will introduce some dynamism into your code: any variable/function you use from tzwhere will be assumed to be of type Any
. Any
类型。 MYPYPATH
environment variable at that folder. MYPYPATH
环境变量指向该文件夹。 Note that this will require a little bit of detective work on your part.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.