简体   繁体   English

mypy 在导入子模块时出错:模块没有属性

[英]mypy gives an error while importing submodule : Module has no attribute

When I am checking my modules through mypy it gives me this error:当我通过 mypy 检查我的模块时,它给了我这个错误:

Module 'django.contrib.gis' has no attribute 'forms'模块“django.contrib.gis”没有属性“forms”

and I am importing forms like this:我正在导入这样的表格:

from django.contrib.gis import forms

I know it is correct but mypy shows this error message.我知道这是正确的,但 mypy 显示此错误消息。

I could import like this: from django.contrib import gis and use forms as gis.forms but I do not want to.我可以这样导入: from django.contrib import gis并使用forms作为gis.forms但我不想。

Can anyone help me to fix this?谁能帮我解决这个问题? Thanks.谢谢。

It appears that your problem is similar to this issue raised in mypy 's github repo:您的问题似乎与mypy的 github 存储库中提出的这个问题类似:

Module X has no attribute Y, since version 0.700 (works fine with 0.670)模块 X 没有属性 Y,因为版本 0.700(适用于 0.670)

wherein the author of the issue originally ran mypy with the following line其中问题的作者最初使用以下行运行mypy

RUN mypy --strict ./mypackage/tests.py

and solved the problem by running mypy by adding on the --implicit-reexport flag as follows:并通过添加--implicit-reexport标志来运行mypy解决了这个问题,如下所示:

RUN mypy --strict --implicit-reexport ./mypackage/tests.py

暂无
暂无

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

相关问题 mypy spurious错误:“module”没有带etree的属性“XPath” - mypy spurious error: “module” has no attribute “XPath” with etree 导入 Pandas 出现错误 AttributeError:模块 'pandas' 在 iPython Notebook 中没有属性 'core' - Importing Pandas gives error AttributeError: module 'pandas' has no attribute 'core' in iPython Notebook 使用“ as”导入时,Python模块没有属性错误 - Python module has no attribute error when importing with an 'as' 导入大熊猫会给出AttributeError'模块'对象没有属性'partial' - Importing pandas gives an AttributeError 'module' object has no attribute 'partial' 从同一目录导入模块时,模块“ a”没有属性“ b” - Module 'a' has no attribute 'b' while importing module from same directory 导入 statsmodels.api 时出错“AttributeError:模块‘scipy’没有属性‘_lib’” - Error While Importing statsmodels.api "AttributeError: module 'scipy' has no attribute '_lib'" 在 python 中导入时安装熊猫后错误:模块“os”没有属性“add_dll_directory” - after installing panda while importing in python Error: module 'os' has no attribute 'add_dll_directory' 出现错误 - AttributeError: 'module' object has no attribute 'connect' - 从 sockets 程序导入时 - Getting the error - AttributeError: 'module' object has no attribute 'connect' - While importing from a sockets program 导入 DASK 时出错:模块 'dask.array' 没有属性 'blockwise' - Error while importing DASK: module 'dask.array' has no attribute 'blockwise' mypy:“联合项目没有属性”错误 - mypy: "Item of Union has no attribute" error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM