Note that the error ImportError: cannot import name 'ImageQt' from 'PIL.ImageQt' can be quite misleading.

If you look at the ImageQt.py source code, you'll see that the ImageQt class is only defined if it successfully detects one of the Qt libraries (pyside2/6, PyQt5/6).

So you can get this error if you have a broken install of Qt. You may want to reinstall PySide6 or whatever you've been using.

You could also use a tool like strace and spy on the Python process (if you're using Linux) to see exactly what it's looking for.

strace python -c 'from PIL.ImageQt import ImageQt'

I used this technique to track down why this import was failing under Docker but working properly on a regular desktop.

For the (Ubuntu) Docker container to properly support the import statement, I had to also install these missing libraries:

apt install -y libegl1 libgl1 libxkbcommon0
Answer from Dodgyrabbit on Stack Overflow
Discussions

ImageQt does not work as expected in PyQt5
What did you do? Attempted to use ImageQt to load a Pillow image in a PyQt5 application What did you expect to happen? I expected the image to load correctly. There are no errors, but it does not l... More on github.com
🌐 github.com
5
February 13, 2021
Traceback: ImportError: cannot import name 'ImageQt' from 'PIL'
When trying to execute it always tracebacks: Traceback (most recent call last): File "/home/snikolov/.local/bin/wingman", line 33, in sys.exit(load_entry_point('wingman... More on github.com
🌐 github.com
1
July 9, 2023
ImageQt missing import
The fromqimage function requires PIL.Image been imported. The following will fail from the command line: $ python -c "from PIL import ImageQt; from PyQt4.QtGui import QImage; qim = QImage(32, ... More on github.com
🌐 github.com
2
November 27, 2015
Import matplotlib qt4 backend after import PIL ImageQt when PyQt5 is installed causes exception
What did you do? from PyQt4 import QtCore from PIL.ImageQt import ImageQt from matplotlib.backends.backend_qt4agg import (FigureCanvasQTAgg as FigureCanvas, NavigationToolbar2QT as NavigationToolba... More on github.com
🌐 github.com
0
November 2, 2017
🌐
Pillow Documentation
pillow.readthedocs.io › en › stable › reference › ImageQt.html
ImageQt module - Pillow (PIL Fork) 12.1.1 documentation
The ImageQt module contains support for creating PyQt6 or PySide6 QImage objects from PIL images.
🌐
GitHub
github.com › python-pillow › Pillow › blob › main › src › PIL › ImageQt.py
Pillow/src/PIL/ImageQt.py at main · python-pillow/Pillow
def fromqimage(im: QImage | QPixmap) -> ImageFile.ImageFile: """ :param im: QImage or PIL ImageQt object · """ buffer = QBuffer() qt_openmode: object ·
Author   python-pillow
🌐
Virtualplants
virtualplants.github.io › _modules › image › pil › ImageQt.html
image.pil.ImageQt — OpenAlea community website
# # history: # 2006-06-03 fl: created # 2006-06-04 fl: inherit from QImage instead of wrapping it # 2006-06-05 fl: removed toimage helper; move string support to ImageQt # 2013-11-13 fl: add support for Qt5 (aurelien.ballier@cyclonit.com) # # Copyright (c) 2006 by Secret Labs AB # Copyright (c) 2006 by Fredrik Lundh # # See the README file for information on usage and redistribution. # from PIL import Image from PIL._util import isPath from openalea.vpltk.qt.QtGui import QImage, qRgba ## # (Internal) Turns an RGB color into a Qt compatible color integer.
🌐
GitHub
github.com › python-pillow › Pillow › issues › 5266
ImageQt does not work as expected in PyQt5 · Issue #5266 · python-pillow/Pillow
February 13, 2021 - import sys from PIL import Image, ImageQt from PyQt5.QtGui import QPixmap, QImage from PyQt5.QtWidgets import QWidget, QLabel from PyQt5.QtWidgets import QVBoxLayout, QApplication class ImageViewer(QWidget): def __init__(self): QWidget.__in...
Author   driscollis
🌐
GitHub
github.com › biqqles › wingman › issues › 37
Traceback: ImportError: cannot import name 'ImageQt' from 'PIL' · Issue #37 · biqqles/wingman
July 9, 2023 - Traceback (most recent call last): File "/home/snikolov/.local/bin/wingman", line 33, in <module> sys.exit(load_entry_point('wingman==5.1', 'gui_scripts', 'wingman')()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/snikolov/.local/bin/wingman", line 25, in importlib_load_entry_point return next(matches).load() ^^^^^^^^^^^^^^^^^^^^ File "/usr/lib64/python3.11/importlib/metadata/__init__.py", line 202, in load module = import_module(match.group('module')) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib64/python3.11/importlib/__init__.py", line 126, in import_module r
Author   hunter86bg
🌐
GitHub
github.com › python-pillow › Pillow › issues › 1557
ImageQt missing import · Issue #1557 · python-pillow/Pillow
November 27, 2015 - The fromqimage function requires PIL.Image been imported. The following will fail from the command line: $ python -c "from PIL import ImageQt; from PyQt4.QtGui import QImage; qim = QImage(32, 32, QImage.Format_ARGB32); im = ImageQt.fromq...
Published   Nov 27, 2015
Find elsewhere
🌐
GitHub
github.com › python-pillow › Pillow › issues › 2827
Import matplotlib qt4 backend after import PIL ImageQt when PyQt5 is installed causes exception · Issue #2827 · python-pillow/Pillow
November 2, 2017 - Python 3.4.5 (default, May 29 2017, 15:17:55) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> >>> import sys >>> >>> 'PyQt4' in sys.modules False >>> 'PyQt5' in sys.modules False >>> >>> from PyQt4 import QtCore >>> 'PyQt4' in sys.modules True >>> 'PyQt5' in sys.modules False >>> >>> from PIL.ImageQt import ImageQt Imported PyQt4...
Author   douglasbeniz
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › programming › python
set imageQt object on QGraphicsView - Raspberry Pi Forums
Now I need to set the current picture (PIL object converted to imageQt) in the widget. If a qr code is detected the function stops. How to set the imageQt object on the QGraphicsView (line 18-19)? Code: ... from threading import Timer def getQR(self): scanner = zbar.ImageScanner() scanner.parse_config('enable') stream = io.BytesIO() with picamera.PiCamera() as camera: camera.start_preview() time.sleep(2) camera.capture(stream, format='jpeg') stream.seek(0) pil = Image.open(stream) pil = pil.convert('L') width, height = pil.size raw = pil.tostring() myQtImage = ImageQt.ImageQt(pil) #How to set image to QGraphicsView?
🌐
Medium
medium.com › xster-tech › creating-pyside-qpixmap-from-pil-image-f93d83aa1b92
Creating PySide QPixMap from PIL Image | by xster | xster | Medium
July 5, 2017 - import sys import PySide sys.modules['PyQt4'] = PySide import Image import ImageQtimage = Image.open(blah) # manipulate image QPixmap(ImageQt.ImageQt(image)) ImageQt is a class provided by PIL that is hardcoded to use PyQt4.
🌐
PyPI
pypi.org › project › pillow › 2.2.1
pip install pillow==2.2.1
Pillow is a functional drop-in replacement for the Python Imaging Library. To run your existing PIL-compatible code with Pillow, it needs to be modified to import the Imaging module from the PIL namespace instead of the global namespace.
      » pip install pillow
    
Published   Oct 02, 2013
Version   2.2.1
🌐
Pillow
hugovk-pillow.readthedocs.io › en › stable › reference › ImageQt.html
ImageQt Module - Pillow (PIL Fork) 10.1.0 documentation
The ImageQt module contains support for creating PyQt6 or PySide6 QImage objects from PIL images.
🌐
Qt Forum
forum.qt.io › home › qt development › language bindings › [solved] pyside, pil image to qpixmap
[SOLVED] Pyside, Pil image to QPixmap | Qt Forum
July 29, 2011 - QImage is not able to parse the current data returned to pil image you need to inform more details to make this possible, you can use that code to create a QImage fom the pil data. ... image = QImage(data, im.size[0], im.size[1], QImage.Format_ARGB32) pix = QPixmap.fromImage(image) lbl = QLabel() lbl.setPixmap(pix) lbl.show()