No name 'QApplication' in module 'PyQt5.QtWidgets' error in Pylint

wolfeyes90 picture wolfeyes90 · Jun 23, 2019 · Viewed 12.2k times · Source

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'"".

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()

I'd expect this error to not keep displaying but its preventing me from running things in VS Code. Any help or suggestions appreciated.

Answer

wolfeyes90 picture wolfeyes90 · Jun 24, 2019

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.