我怎样才能让派林特认出努比成员?

2024-04-28 22:12:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我在一个Python项目上运行PyLint。派林特抱怨说找不到努皮成员。我如何避免这一点,同时避免跳过成员资格检查。

从代码:

import numpy as np

print np.zeros([1, 4])

当我跑的时候,我得到了预期的结果:

[[ 0. 0. 0. 0.]]

但是,pylint给了我这个错误:

E: 3, 6: Module 'numpy' has no 'zeros' member (no-member)

对于版本,我使用pylint 1.0.0(astroid 1.0.1,common 0.60.0),并尝试使用numpy 1.8.0。


Tags: 项目no代码importnumpyas错误np
3条回答

如果将Visual Studio Code与Don Jayamanne的优秀Python extension一起使用,请将用户设置添加到白名单numpy:

{
    // whitelist numpy to remove lint errors
    "python.linting.pylintArgs": [
        "--extension-pkg-whitelist=numpy"
    ]
}

我在这里也有同样的问题,即使是所有相关包的最新版本(astroid 1.3.2logilab_common 0.63.2pylon 1.4.0)。

下面的解决方案很有魅力:我通过修改[TYPECHECK]部分中的pylintrc文件,将numpy添加到忽略的模块列表中:

[TYPECHECK]

ignored-modules = numpy

根据错误,您可能还需要添加以下行(仍位于[TYPECHECK] section):

ignored-classes = numpy

我在一个小的numpy项目中也遇到了同样的错误,我决定忽略numpy模块就可以了。我创建了一个.pylintrc文件,其中:

$ pylint --generate-rcfile > ~/.pylintrc

根据paduwan和júhoug的建议,我修改了以下部分:

[MASTER]

# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code
extension-pkg-whitelist=numpy

以及

[TYPECHECK]

# List of module names for which member attributes should not be checked
# (useful for modules/projects where namespaces are manipulated during runtime
# and thus existing member attributes cannot be deduced by static analysis. It
# supports qualified module names, as well as Unix pattern matching.
ignored-modules=numpy

# List of classes names for which member attributes should not be checked
# (useful for classes with attributes dynamically set). This supports can work
# with qualified names.
ignored-classes=numpy

它“修复”了我的问题。

相关问题 更多 >