Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt5 and QtGui module not found

Is there some reason that QtGui is packaged with PyQt5???

I am using Mark Summerfield's Rapid GUI programming book. Obviously this book was written with Qt4 in mind, but I have been recommended to use Qt5, and PyQt5. I want to run the first example code in chapter 4. The code begins with the following import statements:

import sys
import time
from PyQt5.QtCore import *
from PyQt5.QtGui import *

To which the compiler responds:

Traceback (most recent call last):
  File "wakeUp.py", line 4, in <module>
    from PyQt5.QtGui import *
ImportError: No module named 'PyQt5.QtGui'

Note that the PyQt5.QtCore import statement does not generate an error.

From the terminal,

$ echo $PYTHONPATH
:/usr/lib/python3.3/site-packages

Has anybody else come across this import error for QtGui?

From an interactive session I can

>>> import PyQt5.Qt
>>> import PyQt5.QtDBus
>>> import PyQt5.QtNetwork
>>> import PyQt5.QtXmlPatterns

But I don't have QtWidgets, QtGui, QtWebkit, QtDesigner, and several others.

Also, if it is helpful, the contents of /usr/lib/python3.3/site-packages/PyQt5 are:

__init__.py  QtCore.so  QtDBus.so  QtNetwork.so  Qt.so  QtXmlPatterns.so  uic

which are the same modules that I am able to import. Should the other modules (QtWidgets, QtGui etc) be here too?

I am using Ubuntu 13.04 and Python 3.3.

like image 308
ADB Avatar asked Jun 30 '13 07:06

ADB


People also ask

How do I import QtGui into Python?

Enter the mainloop of application by app.Import QtCore, QtGui and QtWidgets modules from PyQt5 package. Create an application object of QApplication class. Add a QLabel object and set the caption of label as "hello world". Define the size and position of window by setGeometry() method.

What is QtGui in PyQt5?

The QtGui module contains classes for windowing system integration, event handling, 2D graphics, basic imaging, fonts and text. It also containes a complete set of OpenGL and OpenGL ES bindings (see Support for OpenGL).

What is PyQt5 library in Python?

PyQt5 is the latest version of a GUI widgets toolkit developed by Riverbank Computing. It is a Python interface for Qt, one of the most powerful, and popular cross-platform GUI library. PyQt5 is a blend of Python programming language and the Qt library.

What is QtCore PyQt5?

The QtCore module contains the core classes, including the event loop and Qt's signal and slot mechanism. It also includes platform independent abstractions for animations, state machines, threads, mapped files, shared memory, regular expressions, and user and application settings.


1 Answers

The problem was when I was running the PyQt5 configure script. The correct option to pass went like this:

> python3 configure.py --qmake [path to Qt5.x]/bin/qmake

I was providing the path up to bin, but did not specifically point to qmake. Go figure!

After running the configure script like this, I was able to import all the PyQt5 modules.

like image 161
ADB Avatar answered Sep 29 '22 15:09

ADB