I have a very simple PyQt program
import sys
from PyQt4.QtGui import *
app = QApplication(sys.argv)
widget = QWidget()
widget.show()
sys.exit(app.exec_())
When I double click to run the program, it runs successfully. But when I run it in command line: python test.py, I got the following error
Traceback (most recent call last):
File "test.py", line 2, in <module>
from PyQt4.QtGui import *
ImportError: No module named PyQt4.QtGui
The Python "ModuleNotFoundError: No module named 'PyQt5'" occurs when we forget to install the PyQt5 module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install PyQt5 command.
PyQt5 - Introduction PyQt API is a set of modules containing a large number of classes and functions. While QtCore module contains non-GUI functionality for working with file and directory etc., QtGui module contains all the graphical controls.
To install PyQt on Windows there are a few steps you need to take. First use the installer from the qt-project website, from qt to install PyQt. Next you want to install a Python version 3.3 or newer. Check the box to add all of the PyQt5 extras.
Uninstall using uninstall.exe which is provided in your PyQt4/5 folder in site-packages. If you already deleted the folder, just reinstall it with the .exe you first used and try again.
PyQt installation also depends on the version of python installed on your platform.Python3.+ is incompatible with Python version < 3.x.
I was facing the same problem as I have Python 2.7 installed on my machine but I downloaded the latest binary which was PyQt-Py3.2-x86-gpl-4.9.exe. If you see here the binary has python version also mentioned in name after PyQt which is Py3.2. I uninstalled PyQt and installed PyQt-Py2.7-x86-gpl-4.9.exe which points to Python 2.7 and it fixed the problem.
Probably they could have mentioned the naming convention online or in some documentation to be more simpler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With