2

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.

enter image description here

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.

mesafria
  • 311
  • 2
  • 10
  • At first guess, you may have multiple python interpreters installed on your system (since you specified "PyQt5 of 32bits because 64 didn't work for some reason"), so check if you don't have both python 32 and 64 bit installed. It may be that PyCharm is using the wrong interpreter for your project, thus it's not able to resolve the PyQt5 module (which has been installed for the 32 bit version of the python interpreter). If that's not the case you may wanna try to reindex the project (close and reopen PyCharm). – Daniele Pantaleone Oct 06 '15 at 10:02
  • Possible duplicate of [PyCharm can't resolve references to PyQT5 modules](http://stackoverflow.com/questions/43824942/pycharm-cant-resolve-references-to-pyqt5-modules) – Amorphous May 08 '17 at 17:38

4 Answers4

2

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.

Elad Joseph
  • 2,998
  • 26
  • 41
0

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__()
Istlota
  • 84
  • 3
0

In my case I needed in my PyCharm to go File -> Settings -> Project: MyProject -> Project structure and chose correct Project Interpreter

-1

Another probable and easy means is to:

  1. open the command prompt as an administrator
  2. type in 'pip' (without the quotes)
  3. type in: pip show PyQt5 (this shows you where PyQt5 has been installed.
  4. 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.

Chukwunazaekpere
  • 906
  • 1
  • 6
  • 13