Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 458
wolfeyes90 Avatar asked Jun 23 '19 18:06

wolfeyes90


2 Answers

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.

like image 128
wolfeyes90 Avatar answered Sep 21 '22 02:09

wolfeyes90


I think the simplest way to remove package import errors is by going into vscode's JSON settings by Ctrl+Shift+P, search "settings" and choose Preferences: Open Settings (JSON) and adding this line to the dict:

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

If you want to add multiple packages, just add it with the first, separated by a comma like this:

"python.linting.pylintArgs": ["--extension-pkg-whitelist=PyQt5,otherPkg"] 
like image 21
user3625087 Avatar answered Sep 17 '22 02:09

user3625087