首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何让Pylint识别NumPy成员?

如何让Pylint识别NumPy成员?
EN

Stack Overflow用户
提问于 2013-12-13 04:27:12
回答 23查看 97.6K关注 0票数 185

我正在Python项目上运行Pylint。Pylint多次抱怨找不到NumPy成员。我如何避免这种情况,同时避免跳过成员资格检查?

从代码中:

代码语言:javascript
复制
import numpy as np

print np.zeros([1, 4])

当运行时,我得到了预期的结果:

[ 0.0。0。0。]

然而,Pylint给了我这个错误:

E: 3,6:模块'numpy‘没有’零‘成员(无成员)

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

EN

回答 23

Stack Overflow用户

发布于 2016-09-15 06:43:10

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

代码语言:javascript
复制
{
    // Whitelist NumPy to remove lint errors
    "python.linting.pylintArgs": [
        "--extension-pkg-whitelist=numpy"
    ]
}
票数 85
EN

Stack Overflow用户

发布于 2015-01-14 20:50:17

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

下面的解决方案非常好用:我在[TYPECHECK]部分修改了我的pylintrc文件,将numpy添加到了被忽略的模块列表中:

代码语言:javascript
复制
[TYPECHECK]

ignored-modules = numpy

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

代码语言:javascript
复制
ignored-classes = numpy
票数 61
EN

Stack Overflow用户

发布于 2016-02-08 06:29:20

我在一个正在处理的小型NumPy项目中遇到了同样的错误,并决定忽略NumPy模块就可以了。我创建了一个包含以下内容的.pylintrc文件:

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

遵循paduwan'sj_houg's的建议,我修改了以下部分:

代码语言:javascript
复制
[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

代码语言:javascript
复制
[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

它“修复”了我的问题。

票数 50
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20553551

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档