1

I've recently started to use PyQT5. However, I'm facing several errors which are being generated yet the application it self is still working. All of the errors are for undefined variables for PyQT related modules.

E.G. "Undefined variable 'QApplication' pylint(undefined-variable).

As im following a tutorial with no real expertise in PyQT or pylint im unsure as to what this is and how detrimental this is to my project. Can this be solved, if so how? if not, is there a possible work around?

Below is not the exact code I originally reported this error on (I'm only following a tutorial therefore none of it is complex code) however the following produces the exact same error which suggests it is indeed not the script itself and is likely a visual studio code or Pylint issue.

import sys
import time
# Self explanatory.
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

# Create QApplication Object. Something all applications must have one of.
app = QApplication(sys.argv)
Chad Langford
  • 11
  • 1
  • 3

1 Answers1

1

The problem is not with the PyQT5. It is the problem with VS Code. The PyLint in your VS Code build can't understand the PyQT5 variables. It is because Pylint doesn't support Dynamic Modules like PyQT5. https://github.com/Microsoft/vscode-python/issues/261

To solve the problem follow these rules:

  1. Go to the VS Code User directory normally located at following path

    • Windows : %APPDATA%\Code\User\settings.json
    • macOS : $HOME/Library/Application Support/Code/User/settings.json
    • Linux : $HOME/.config/Code/User/settings.json
  2. Open settings.json file.

  3. Write following command at the end of the file:
   {
    "python.linting.pylintArgs": ["--extension-pkg-whitelist=PyQt5"]
   }
  1. Save the file.
  2. Run your code and tell me if the error is fixed or not.
  • Unfortunately it does not work. In fact it produced some white space errors too. – Chad Langford Oct 31 '19 at 22:07
  • I had accidently written cv2 instead of PyQt5. Try again with replacing cv2 with PyQt5 after --extension-pkg-whitelist= .I already edited the answer. – Hussain Abdullah Oct 31 '19 at 22:12
  • I have made the changes as requested and the error still remains. – Chad Langford Oct 31 '19 at 22:17
  • @ChadLangford Try [changing your linter](https://code.visualstudio.com/docs/python/linting#_specific-linters) to `flake8`. According to [this vscode issue](https://github.com/Microsoft/vscode-python/issues/2817#issuecomment-428408443), the problem is specific to pylint. – ekhumoro Oct 31 '19 at 22:18
  • try putting "python.linting.pylintArgs": ["--extension-pkg-whitelist=PyQt5"] in already present { } instead of creating new ones. – Hussain Abdullah Oct 31 '19 at 22:22
  • and don't forget to put comma at the end of second last line while entering "python.linting.pylintArgs": ["--extension-pkg-whitelist=PyQt5"] in already present brackets. – Hussain Abdullah Oct 31 '19 at 22:32
  • You hit the nail on the head Hussain. Thank you very much. I appreciate the help! – Chad Langford Oct 31 '19 at 22:35