在尝试学习 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"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!