pylint 找不到 QWidget 和 QApplication [英] pylint can't find QWidget and QApplication

查看:27
本文介绍了pylint 找不到 QWidget 和 QApplication的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

import sys
from PyQt5.QtWidgets import (QApplication, QWidget)
app = QApplication(sys.argv)
window = QWidget()
window.setGeometry(50, 50, 500, 300)
window.setWindowTitle('Hello, world')
window.show()
sys.exit(app.exec_())

我刚开始学习pyqt5.我写了这个 hello world 应用程序,它有效.但是 pylint 给出了E0611:No name 'QWidget' in module 'PyQt5.QtWidgets'",QApplication 也是如此.这是pylint中的某种错误吗?

I just started to learn pyqt5. I wrote this hello world app, which works. But pylint gives "E0611:No name 'QWidget' in module 'PyQt5.QtWidgets'" and same for QApplication. Is it some kind of bug in pylint?

pylint --version
No config file found, using default configuration
pylint 1.7.2, 
astroid 1.5.3
Python 3.5.2 (default, Aug 18 2017, 17:48:00) 
[GCC 5.4.0 20160609]

推荐答案

(Ubuntu) 我创建了一个 ~/.pylintrc 文件并添加到那里

(Ubuntu) I've created a ~/.pylintrc file and added there

[MASTER]
extension-pkg-whitelist=PyQt5

这样更方便.现在 pylint 甚至在我的 Visual Studio Code 编辑器中也应用了这个配置.

It is more convenient. And now pylint applies this configuration even in my Visual Studio Code editor.

或者在 VSCode 设置中:

Or in VSCode settings:

"python.linting.pylintArgs": [
    "--extension-pkg-whitelist=PyQt5"
],

这篇关于pylint 找不到 QWidget 和 QApplication的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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