站內搜尋:Yahoo搜尋的結果,如果沒有給完整的網址,請在站內再搜尋一次!

2019-08-23

VS Code : pylint 出現錯誤訊息:No name 'QApplication' in module 'PyQt5.QtWidgets',解決方法

  1. 錯誤訊息:No name 'QApplication' in module 'PyQt5.QtWidgets'
  2. 訊息內容:
    {
    "resource": "/d:/MyWorkSpaces/VSWorks/ch04/qt04_lineEdit04.py",
    "owner": "python",
    "code": "no-name-in-module",
    "severity": 8,
    "message": "No name 'QApplication' in module 'PyQt5.QtWidgets'",
    "source": "pylint",
    "startLineNumber": 5,
    "startColumn": 1,
    "endLineNumber": 5,
    "endColumn": 1
    }

  3. 錯誤原因:
    跟所使用的Pylint有關,所採用的版本預設不支援外部擴充模組(Extenions),PyQt5是C++所寫的外部擴充(Extension)。
  4. 解決方法:
    • VS Code : 檔案→喜好設定→設定
    • 在設定的搜尋方塊中輸入:python.linting.pylintArgs
      新增項目,輸入:--extension-pkg-whitelist=PyQt5
    • 設定資料會被寫入:setting.json
    • No name 'QApplication' in module 'PyQt5.QtWidgets' 等模組錯誤的訊息消失了
      from的下曲紅底線,不見了 ...

沒有留言:

張貼留言