VSCODE 报错 Module ‘xx‘ has no ‘xx‘ member pylint(no-member)

Posted 呆呆象呆呆

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VSCODE 报错 Module ‘xx‘ has no ‘xx‘ member pylint(no-member)相关的知识,希望对你有一定的参考价值。

1 问题描述

VSCODE报错Module 'xx' has no 'xx' member pylint(no-member)
一般会出现的问题:在写python的时候发现红色提示pylint(no-member)'xx'为库中的某个函数或者类

Module 'numpy' has no 'xx' member pylint(no-member)
Module 'torch' has no 'xx' member pylint(no-member)
Module 'cv2' has no 'xx' member pylint(no-member)

2 问题分析

pylint是vscode的python语法检查器,pylint是静态检查,在用第三方库的时候有些成员只有在运行代码的时候才会被建立,它就找不到成员,在设置(settings.json)里添加针对这种情况的不检查报错即可。

3 问题解决

3.1 直接打开settings.josn

打开设置的命令面板或者直接使用快捷键ctrl+shift+P

在命令面板输入settings,选择首选项:打开设置

3.2 修改配置文件

最简单的修改方式:在配置文件中添加如下的内容

"python.linting.pylintArgs": ["--generate-members"],

但是这个修改方式其实还是有一些问题,因为他会屏蔽所有生成成员类的错误,我们只需要在某些库中对这种特殊情况进行规避即可。(否则当自己的代码有问题的时候他也不报错就会出现不想要发生的错误)

所以我们使用如下的修改方式

"python.linting.pylintArgs": [
"--errors-only",
"--generated-members=numpy.* ,torch.* ,cv2.* , cv.*"
],

errors-only is not realted to the issue but is useful to suppress pep 8/formatting “errors” if you want to

Last 参考文献

VS Code报错Module ‘xx’ has no ‘xx’ member pylint(no-member)_ngy321的博客-CSDN博客

[Minor Bug] Pylint E1101 Module ‘torch’ has no ‘from_numpy’ member · Issue #701 · pytorch/pytorch

以上是关于VSCODE 报错 Module ‘xx‘ has no ‘xx‘ member pylint(no-member)的主要内容,如果未能解决你的问题,请参考以下文章

VS Code报错Module 'xx' has no 'xx' member pylint(no-member)解决办法

VScode中pytorch出现Module 'torch' has no 'xx' member错误

vscode:Module ‘“xxx/node_modules/vue/dist/vue“‘ has no exported member ‘ref‘

from keras.preprocessing.text import Tokenizer报错:AttributeError: module ‘tensorflow.compat.v2‘ has..

python报错: AttributeError module 'time' has no attribute 'clock'

Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法