問題描述
在嘗試學習 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模板網!