Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt Import Error

Tags:

python

pyqt

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
like image 703
Byron Avatar asked Jun 12 '11 06:06

Byron


People also ask

How to fix No module named PyQt5?

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.

What is PyQt5 QtCore?

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.

How do I get PyQt5?

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.

How do I remove PyQt5 from Windows?

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.


1 Answers

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.

like image 157
Navneet Avatar answered Oct 21 '22 00:10

Navneet