22
import sys
from PyQt5.QtWidgets import (QApplication, QWidget)
app = QApplication(sys.argv)
window = QWidget()
window.setGeometry(50, 50, 500, 300)
window.setWindowTitle('Hello, world')
window.show()
sys.exit(app.exec_())

I just started to learn pyqt5. I wrote this hello world app, which works. But pylint gives "E0611:No name 'QWidget' in module 'PyQt5.QtWidgets'" and same for QApplication. Is it some kind of bug in pylint?

pylint --version
No config file found, using default configuration
pylint 1.7.2, 
astroid 1.5.3
Python 3.5.2 (default, Aug 18 2017, 17:48:00) 
[GCC 5.4.0 20160609]
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Sergey
  • 421
  • 1
  • 5
  • 14
  • execute: `pylint your_file.py -rn --extension-pkg-whitelist=PyQt5 --disable=blacklisted-name,invalid-name,missing-docstring` – eyllanesc Sep 21 '17 at 20:45
  • Does this answer your question? [No name 'QApplication' in module 'PyQt5.QtWidgets' error in Pylint](https://stackoverflow.com/questions/56726580/no-name-qapplication-in-module-pyqt5-qtwidgets-error-in-pylint) – bers Jan 20 '23 at 09:17

3 Answers3

29

(Ubuntu) I've created a ~/.pylintrc file and added there

[MASTER]
extension-pkg-whitelist=PyQt5

It is more convenient. And now pylint applies this configuration even in my Visual Studio Code editor.

Or in VSCode settings:

"python.linting.pylintArgs": [
    "--extension-pkg-whitelist=PyQt5"
],
Winand
  • 2,093
  • 3
  • 28
  • 48
slavugan
  • 1,463
  • 17
  • 17
  • 3
    If you want to keep the default linting rules, you need to add two more pylintArgs, "--disable=all", "--enable=F,E,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode" because by specifying values in pylintArgs, this [implicitly sets pylintUseMinimalCheckers to false](https://code.visualstudio.com/docs/python/linting) (at least in Visual Studio Code). See end of section on Default Pylint rules. – Martin Jun 19 '19 at 16:42
  • Thank you, you are an amazing person. – John Smith Optional Nov 01 '19 at 15:13
  • can you confirm the suggested fix works on VSCode. I inserted exactly that in Settings in VSCode at the end of the default configurations, I did not click "Add configurations" instead simply typed a "," after the exiting configuration and added the suggested whitelisting code, then I restarted VSCode, but I get the same error. – Echeban Nov 09 '19 at 23:36
  • @Echeban, it worked in 2017. but now I'm not sure, I don't work with Qt anymore. – slavugan Nov 11 '19 at 10:09
  • 1
    I can confirm it works on VSCode 2019. After the last `]` I added exactly this `, "python.linting.pylintArgs": ["-rn --extension-pkg-whitelist=PyQt5 --disable=blacklisted-name,invalid-name,missing-docstring"]` – Echeban Nov 20 '19 at 20:26
  • @Echeban With this configuration you disabled pylint. This configuration is invalid and pylint can't work. – Thomas Sablik Aug 24 '20 at 23:46
4

I found solution in this page: http://python.6.x6.nabble.com/PyQt-and-pylint-with-quot-no-name-in-module-quot-td5217888.html

so using it in terminal as (for main.py):

pylint main.py --extension-pkg-whitelist=PyQt5
AOK
  • 53
  • 6
  • 2
    Do you understand the reason for the error? The linked forum states that *pylint doesn't load any C extensions by default*. I'm not familiar enough with the inner workings of `pyqt` to understand what this means... but it seems like some sort of security feature specific to python wrappers for C/C++? If possible, some elaboration of the cause of this error would be appreciated! – RTbecard Nov 10 '18 at 18:36
  • @RTbecard Since the pyqt is written in C, pylint cannot introspect it like it can with normal python code, so it incorrectly concludes that the name doesn't exist in the module. – cdignam Jul 22 '19 at 02:36
0

It is mostly caused by the combination of Qt5 and Pylint. So if you are using VsCode update it in the workspace setting.

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


peerpressure
  • 390
  • 4
  • 19