Pylint 中的模块“PyQt5.QtWidgets"中没有名称“QApplication"错误 [英] No name 'QApplication' in module 'PyQt5.QtWidgets' error in Pylint

查看:109
本文介绍了Pylint 中的模块“PyQt5.QtWidgets"中没有名称“QApplication"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试学习 PyQt5 时在 VS Code 中遇到这个问题,模块‘PyQt5.QtWidgets’中没有名称‘QApplication’",模块‘PyQt5.QtWidgets’中没有名称‘QWidget’".

Running into this issue in VS Code while trying to learn PyQt5, "No name 'QApplication' in module 'PyQt5.QtWidgets'", "No name 'QWidget' in module 'PyQt5.QtWidgets'"".

我不确定这是pylint问题还是其他问题.我已经确认 PyQt5 与 pip3 list 一起安装,但我似乎无法弄清楚问题所在.

I'm not sure if this is a pylint issue or something else. I've confirmed PyQt5 is installed with pip3 list but I can't seem to figure out the issue.

import sys
from PyQt5.QtWidgets import QApplication, QWidget

def app():
  my_app = QApplication(sys.argv)
  w = QWidget()
  w.setWindowTitle("Test")
  w.show()
  sys.exit(my_app.exec_())
app()

我希望此错误不会继续显示,但会阻止我在 VS Code 中运行内容.任何帮助或建议表示赞赏.

I'd expect this error to not keep displaying but its preventing me from running things in VS Code. Any help or suggestions appreciated.

推荐答案

我已经解决了这个问题,显然 Pylint 默认不加载任何 C 扩展,因为它们可以运行任意代码. 所以我发现如果你在你的项目目录中创建一个名为 .pylintrc 的文件的系统文件,rc 文件可以通过在 rc 文件中添加以下代码将这个包列入白名单以停止抛出错误 extension-pkg-whitelist=PyQt5.所以本质上问题不是 PyQt5,而是由于这个原因导致的 linter 抛出错误错误.

I've figured out the issue, apparently Pylint doesn't load any C extensions by default, because those can run arbitrary code. So I found that if you create a system file in your project directory with the file named .pylintrc the rc file can whitelist this package to stop throwing errors by adding the following code in the rc file extension-pkg-whitelist=PyQt5. So essentially the issue isn't PyQt5, it was the linter throwing false errors due to this.

这篇关于Pylint 中的模块“PyQt5.QtWidgets"中没有名称“QApplication"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆