This question already has answers here:
pylint can't find QWidget and QApplication
(3 answers)
Closed 3 years ago.
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)
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:
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
Open settings.json file.
Write following command at the end of the file:
{
"python.linting.pylintArgs": ["--extension-pkg-whitelist=PyQt5"]
}
Save the file.
Run your code and tell me if the error is fixed or not.
Related
I use vscode as my python IDE, and had installed some nessary plugins such as python and pylance for it. But now I have a problem, the pylance for vscode could not reconizge the PySide6 modules for quick fix auto import, like following picture shows:
But the quick fix work for other modules.
Could someone help to point out how to resolve it? It worked before but one day could not work any more.
Sorry, but normally, we will not act like this. We will not type a complex or long className then import it through a quick fix. at most we type sys and import it immediately.
The problem is that, when I try to import a certain class from a .py archive that is in the same package it gives me an error. I have tried using from .something import function, from something import function and both ways end in error.
So your question is kinda vague but ive had a similar issue from what I understand in sublime text
to solve this make sure you have the correct python interpreter on visual studio
I have installed PyQt5 using the windows installer. I have tried creating some windows and stuff and it works great. Still, pycharm seems to not like PyQt5 very much, and is marking errors everywhere in my code.
As I said, PyQt5 is working great, but it's kind of annoying to have those errors which, by the way, i can not alt + enter + ignore them.
I guess it's just a matter of adding references or something to pycharm, but I have no idea how to do it and I have already spent 1 hour trying to look for solutions in stack-overflow, and none of them work. I have also tried re-installing it.
I am using windows 7 64 bits, python 3.4, and PyQt5 of 32bits because 64 didn't work for some reason.
I had similar problem because I had both PyQt4 and PyQt5 installed.
In general this can cause all sorts of problem, so the spyder-ide guys made the qtpy package, which gives an abstraction on top of the PyQt5/PyQt4/PySide.
Nowdays the qtpy is a standard library in the Anaconda distribution, and you can call it instead of PyQt5/PySide likes this:
from qtpy.QtCore import QFile, QFileInfo
from qtpy.QtGui import QIcon, QKeySequence, QPixmap
It solved me this specific problem in PyCharm.
I also have both 32 bit and 64 bit Python v3.5 and PyQt5 versions installed. That should not matter because I installed the 32 bit PyQt5 package in the 32 bit PI and the 64 bit PyQt5 package in the 64 bit PI. I installed the PyQt5 packages from Riverbanks's PyQt5 web site. Christopher Gohlke does not have them yet on his Windows extensions site, nor does PyCharm's PI dialog even list PyQt5 as an available package.
PyCharm does indeed incorrectly flag numerous warnings whether I choose the 32 bit PI or the 64 bit PI for the PyQt5 project I am working on. This appears to be a cosmetic bug only for PyQt5 code, since the code does run correctly, even if I run the code from PyCharm's Terminal window. Also, note that PyQt5 is not listed in PyCharm's PI settings dialog, even though Windows 10 File Explorer does indeed list the proper packages in the proper site-packages folder. Doing a PyCharm Invalidate/Restart does not help.
That said, you do not have to, nor should you, suppress warnings for everything. Just suppress warnings on a case by case basis only for PyCharm's incorrect PyQt5 warnings. You can do it like this:
def __init__(self):
# noinspection PyArgumentList
super().__init__()
In my case I needed in my PyCharm to go File -> Settings -> Project: MyProject -> Project structure and chose correct Project Interpreter
Another probable and easy means is to:
open the command prompt as an administrator
type in 'pip' (without the quotes)
type in: pip show PyQt5 (this shows you where PyQt5 has been installed.
follow the trace given to you from the command prompt. Now, open the folder 'site-packages' and copy every folder termed' PyQt5' to the 'lib' folder instead (ignoring those with '.. - info' is inconsequential).
In Pycharm or Visual studios, the red underline goes off and the problem of 'unresolved reference' is eliminated.
I'm introducing myself to PyQt5 through one of its included examples. On this windows 7 machine, I have installed Python 3.4 x64, and PyQt5 using its binary provided on riverbankcomputiong.com. The documentation says that the binary already includes everything necessary to run. I (perhaps incorrectly) assumed that i can safely skip the "configure" and "build" steps at Riverbank's installation guide, since the guide only talks about .zip, .tar, etc. files.
I used the tutorial located here:
http://www.pythonschool.net/pyqt/introduction-to-pyqt/
Which also says "just run the binary to install pyqt4 there is no step three."
When i attempt to run any tutorial containing reference to PyQt4 or PyQt5:
from PyQt5.QtCore import *
I get the following error message:
ImportError: DLL load failed: The specified module could not be found.
But when i enter the following:
import PyQt5
The interpreter seems to be okay with it -- no errors.
I can't help but think I've done something wrong installation, because even when I run the examples included with PyQt4/PyQt5, i get importerrors. It seems as though QtCore doesn't even exist in relation to PyQt4 or PyQt5. What's going on here?
There seem to be a few possibilities:
You might need to update your PATH environment variable to include the location where the library is installed (i.e. directory location where the DLLs are)
Take note of where you're launching the interpreter or scripts from as their current path may not necessarily include what you expect.
You can check this with:
>>> import os
>>> os.environ['PATH'].split(os.pathsep)
Make sure the installation process was truly successful (i.e. zero errors) and that you downloaded the correct binary package for your PC's architecture.
I ran into a similar issue with PySide where import PySide would work but import PySide.QtCore would fail.
I'd expect the code to work after verifying those things:
>>> from PyQt5.QtCore import *
>>>
If it doesn't, update the question with additional details like things you checked, their values, error messages, etc.
On my office PC I'm using
Python 3.4
PyQt4 Version 4.11.1
PyCharm Community Eddition 3.4.1
I installed everything in the order as stated above.
However, code completion does not work. It works for imports, but not for classes and methods.
I made a small sample program:
import sys
from PyQt4 import QtGui
app = QtGui.QApplication(sys.argv)
window = QtGui.QWidget()
window.setWindowTitle("Test")
window.resize(300, 200)
window.show()
sys.exit(app.exec_())
In the code above none of the classes or methods were suggested by PyCharm.
If I type window.setW I would expect it to suggest setWindowTitle() but it doesn't.
Strange thing is, that I'm using the same setup on my computer at home and there it works like a (Py)charm... Autocompletion, auto imports, etc. As far as I remember I installed it the same way as I did on my office PC.
I already looked at some similiar questions but this question has no answers and others don't contain relevant information that helped me so far.
Don't know if it is relevant but at this line
from PyQt4 import QtGui
PyCharm tells me
Unresolved reference 'QtGui'
Maybe the reason for this is the same.
I had the same problem on Linux, pyqt5 and pycharm CE.
The solution was to rebuild the skeletons with:
File > Invalidate Caches / Restart > Invalidate and Restart.
The problem was solved by installing PyCharm first and then Python and PyQt.
Afterwards I had to configure the interpreter in PyCharm and it worked.
When I posted the question I installed Python, then PyQt and then PyCharm.
Oddly enough, it worked in this order on another PC.
I went through the same issue recently. Unfortunately, the install order didn't solve it for me.
There is a bug report here. Downloading the Early Access Program release worked and can be found here