No name #39;QApplication#39; in module #39;PyQt5.QtWidgets#39; error in Pylint(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 列表,但我似乎无法找出问题所在.
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"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Pylint 中的模块“PyQt5.QtWidgets"错误中没有名称“QApplication"
基础教程推荐
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 包装空间模型 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
