Alp*_*a14 156 python numpy pylint
我正在Python项目上运行PyLint.PyLint对无法找到numpy成员提出了许多抱怨.如何在避免跳过成员资格检查的同时避免这种情况.
从代码:
import numpy as np
print np.zeros([1, 4])
Run Code Online (Sandbox Code Playgroud)
哪,跑了,我得到了预期的:
[[0. 0. 0. 0.]]
但是,pylint给了我这个错误:
E:3,6:模块'numpy'没有'零'成员(无成员)
对于版本,我使用pylint 1.0.0(astroid 1.0.1,常见的0.60.0)并尝试使用numpy 1.8.0.
Dav*_*rke 73
如果将Visual Studio代码与Don Jayamanne的优秀Python扩展一起使用,请将用户设置添加到白名单numpy:
{
// whitelist numpy to remove lint errors
"python.linting.pylintArgs": [
"--extension-pkg-whitelist=numpy"
]
}
Run Code Online (Sandbox Code Playgroud)
小智 58
我这里有同样的问题,即使有(所有相关的软件包的最新版本astroid 1.3.2,logilab_common 0.63.2,pylon 1.4.0).
以下解决方案就像一个魅力:我numpy通过修改我的pylintrc文件添加到被忽略的模块列表中,在以下[TYPECHECK]部分中:
[TYPECHECK]
ignored-modules = numpy
Run Code Online (Sandbox Code Playgroud)
根据错误,您可能还需要添加以下行(仍在[TYPECHECK] section)中:
ignored-classes = numpy
Run Code Online (Sandbox Code Playgroud)
小智 40
对于我正在研究的小型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
Run Code Online (Sandbox Code Playgroud)
和
[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
Run Code Online (Sandbox Code Playgroud)
它"修复"了我的问题.
bij*_*ncn 17
由于这是谷歌的最佳结果,它给我的印象是你必须忽略所有文件中的警告:
上个月https://bitbucket.org/logilab/astroid/commits/83d78af4866be5818f193360c78185e1008fd29e已经解决了pylint/astroid来源中的问题, 但还没有在Ubuntu软件包中.
只是为了得到消息来源
hg clone https://bitbucket.org/logilab/pylint/
hg clone https://bitbucket.org/logilab/astroid
mkdir logilab && touch logilab/__init__.py
hg clone http://hg.logilab.org/logilab/common logilab/common
cd pylint && python setup.py install
Run Code Online (Sandbox Code Playgroud)
最后一步很可能需要一个sudo,当然你需要mercurial来克隆.
Spa*_*atz 11
为了忽略numpy.core属性生成的所有错误,我们现在可以使用:
$ pylint a.py --generated-members=numpy.*
Run Code Online (Sandbox Code Playgroud)
作为另一种解决方案,将此选项添加到〜/ .pylintrc或/ etc/pylintrc文件中:
[TYPECHECK]
# List of members which are set dynamically and missed by pylint inference
# system, and so shouldn't trigger E1101 when accessed. Python regular
# expressions are accepted.
generated-members=numpy.*
Run Code Online (Sandbox Code Playgroud)
对于现在提到的问题代码,这似乎是简化的,但仍然对另一个模块很重要,即.netifaces等
lai*_*jay 11
如果您不想添加更多配置,请将此代码添加到您的配置文件中,而不是“白名单”。
{
"python.linting.pylintArgs": ["--generate-members"],
}
Run Code Online (Sandbox Code Playgroud)
在过去的几年里,有很多不同的错误报道,例如https://bitbucket.org/logilab/pylint/issue/58/false-positive-no-member-on-numpy-imports
我建议禁用发生投诉的线路.
# pylint: disable=E1103
print np.zeros([1, 4])
# pylint: enable=E1103
Run Code Online (Sandbox Code Playgroud)
可能,它与numpy的方法导入的深奥方法相混淆.即,zeros实际上numpy.core.multiarray.zeros是在numpy中导入语句
from .core import *
Run Code Online (Sandbox Code Playgroud)
反过来导入
from .numeric import *
Run Code Online (Sandbox Code Playgroud)
你会发现数字
zeros = multiarray.zeros
Run Code Online (Sandbox Code Playgroud)
我想我会被困在PyLint的位置!
请参阅此错误以了解PyLint的一面.
我在一个不同的模块 ( kivy.properties) 上遇到了同样的问题,它是一个像 NumPy 这样的封装 C 模块。
使用 Visual Studio Code V1.38.0,已接受的解决方案停止了项目的所有 linting。因此,虽然它确实消除了误报no-name-in-module,但并没有真正改善情况。
对我来说最好的解决方法是--ignored-modules在有问题的模块上使用参数。问题是,通过传递任何参数会python.linting.pylintArgs清除默认的 Visual Studio Code 设置,因此您还需要重置这些设置。这给我留下了以下settings.json文件:
{
"python.pythonPath": "C:\\Python\\Python37\\python.exe",
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"python.linting.pylintArgs": [
"--ignored-modules=kivy.properties",
"--disable=all",
"--enable=F,E,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode"
]
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
69789 次 |
| 最近记录: |