简体   繁体   English

mypypath:找不到名为“ tzwhere”的模块

[英]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(如果我们稍作简化的话)本质上检查存根的两个不同位置:

  1. It checks a local copy of typeshed , which is a repository of type hints for the standard library and popular 3rd party libraries. 它检查typeshed的本地副本,后者是标准库和流行的3rd party库的类型提示存储库。 (A copy of typeshed is automatically installed alongside mypy.) (键入的副本会自动与mypy一起安装。)
  2. It checks if the package itself is bundling type hints (eg if the package is a PEP 561 compliant package). 它检查程序包本身是否为捆绑类型提示 (例如,程序包是否为符合PEP 561的程序包)。

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: 您有三个主要选择:

  1. Just suppress the error message by adding a # 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 . 请注意,这将在代码中引入动态性:您从tzwhere中使用的任何变量/函数都将被假定为Any类型。
  2. Create type stubs for the module, store it in a folder somewhere, and point the MYPYPATH environment variable at that folder. 为模块创建类型存根,将其存储在某个位置的文件夹中,然后将MYPYPATH环境变量指向该文件夹。 Note that this will require a little bit of detective work on your part. 请注意,这将需要您进行一些侦探工作。 More details on how mypy finds imports here . 有关mypy如何在此处查找导入的更多详细信息
  3. If you want to share your work from step 2 with others, either submit a pull request to typeshed with your stubs or submit a pull request with tzwhere itself to turn it into a PEP 561 compliant package. 如果要与其他人共享第2步中的工作,请提交与存根进行排版的拉取请求,或者使用tzwhere本身提交拉取请求,以将其转换为符合PEP 561的程序包。 Make sure you get an ok from the author of the library before doing either of these things. 在执行上述任何一项操作之前,请确保您从库的作者那里得到了同意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ImportError:没有名为tzwhere的模块 - ImportError: No module named tzwhere mypy 给出错误即使在添加 MYPYPATH 之后也找不到名为 math_func 的模块的实现或库存根 - mypy giving error Cannot find implementation or library stub for module named math_func even after adding MYPYPATH 在Python 3中使用“ tzwhere”模块 - Using “tzwhere” module in Python 3 DjanoRestFramework应用程序找不到名为“ graphene_django”的模块 - DjanoRestFramework App Cannot Find Module Named 'graphene_django' Spyder 找不到名为“pandas_datareader”的模块 - Spyder cannot find module named 'pandas_datareader' pyttsx错误(mac):找不到名为foundation的模块 - pyttsx error (mac): cannot find module named foundation pyinstaller错误:找不到scipy(没有名为_ufuncs_cxx的模块) - pyinstaller error: cannot find scipy (No module named _ufuncs_cxx) Sphinx 找不到我的 python 文件。 说“没有模块命名...” - Sphinx cannot find my python files. Says 'no module named ...' 我可以禁用 MyPy 的“找不到名为...的模块的实现或库存根”错误吗? - Can I disable MyPy's "Cannot find implementation or library stub for module named..." error? Python无法从二级深子目录中找到名为/导入错误的模块 - Python cannot find module named / Import error from two level deep subdir
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM