Pycharm import error with Pyqt4 and Pyqt5
In PyCharm File > Invalidate Caches
worked for me.
https://stackoverflow.com/a/11773462/999943
Hope that helps.
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Admin
Updated on June 07, 2022Comments
-
Admin about 2 years
I'm having some troubles with PyQt. I've installed PyQt4 and PyqQt5 through Homebrew, and I planned on using PyQt4 for a particular project I'm working on. However, I have some strange issues getting it to work.
In one module, we'll call it A, I'm using these imports:
from OpenGL.GL import * from OpenGL.GLU import * from PyQt4 import QtGui from PyQt4.QtOpenGL import *
Now, PyQt4 is red underlined with 'unresolved reference to PyQt4'. However, this code runs. If I change it to PyQt5, there is no underline:
from OpenGL.GL import * from OpenGL.GLU import * from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtOpenGL import *
But, I get this error when running:
Traceback (most recent call last): File "/Users/Jordan/PycharmProjects/SimpleCAD/QGLWindow.py", line 6, in <module> from PyQt5 import QtCore, QtGui, QtWidgets ImportError: No module named PyQt5
Now, I have another window in my program, which I've taken care of in a different module, B. Those imports look like this:
import sys from PyQt4 import QtGui
When I run this code, I get this error:
Traceback (most recent call last): File "/Users/Jordan/PycharmProjects/SimpleCAD/QTMainWindow.py", line 2, in <module> from PyQt4 import QtGui ImportError: No module named 'PyQt4'
So, what's going on with my imports here? Why does PyQt4 work in one module, but not another? And why am I getting warnings for PyQt4 imports that work in one module, but none for the unworking PyQt5 imports? Thanks for any help in advance.
-
Lenormju almost 5 yearsRebuilding the caches may be a bit long, but it did work for me.