opencv-python: Could not find the Qt platform plugin "wayland" in opencv path

Expected behaviour

Write here how did you expect the library to function.

Actual behaviour

Write here what went wrong.

Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
qt.qpa.plugin: Could not find the Qt platform plugin "wayland" in "/home/firefly/venv/lib/python3.9/site-packages/cv2/qt/plugins"
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: xcb.

Aborted (core dumped)

Steps to reproduce

  • example code
import cv2
cap=cv2.VideoCapture(8)
while True:
    ret,frame =cap.read()
    frame=cv2.flip(frame,1)
    cv2.imshow('frame',frame)
    if cv2.waitKey(1)&0xff==ord('q'):
        break
cap.release()
cv2.destroyAllWindows()
  • operating system: ubuntu 20.04
  • architecture (e.g. x86): aarch64
  • opencv-python version: opencv_python-4.5.1.48-cp39-cp39
Issue submission checklist
  • This is not a generic OpenCV usage question (looking for help for coding, other usage questions, homework etc.)

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 5
  • Comments: 25

Most upvoted comments

@mahyarmirrashed yes it is. So there 3 ways I 've proven to work to suppress this message:

  1. use os.environ.pop("QT_QPA_PLATFORM_PLUGIN_PATH") after import cv2
  2. try sudo pip install opencv-python-headless
  3. delete the libqxcb frm OpenCV in /home/yourname/.local/lib/python3.9/site-packages/cv2/qt/plugins/platforms

In the Thonny IDE commen in no. 1 works fine should in terminal too.

i also have same problem with latest version of opencv-python.If any one was able to solve this issue please reply here.

OpenCV distributes own instance of QT to facilitate imshow and some other UI functions. Own QT built is done without wayland support: https://github.com/opencv/opencv-python/blob/4.x/docker/manylinux2014/Dockerfile_x86_64#L59. I’ll take a look if we can add this option to the package for the next release.

I have the same problem for opencv-python 4.5.x,4.6.x, the error message is

Connected to pydev debugger (build 201.8538.36)
QObject::moveToThread: Current thread (0x55ae47946190) is not the object's thread (0x55ae4795d6b0).
Cannot move to target thread (0x55ae47946190)

qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/hitbuyi/.conda/envs/py1121/lib/python3.9/site-packages/cv2/qt/plugins" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: xcb, eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl.

My environments are OS: ubuntu20.04 Conda: 4.43 python: 3.9 opencv-python: 4.5.x,4.6.x

Any progress in this issue?

QT_QPA_PLATFORM=xcb

If you’re not in conda environment, this solution will work best

pip3 install opencv_python
export QT_QPA_PLATFORM=xcb

this will work best in the current on terminal only. For permanent change do

echo "export QT_QPA_PLATFORM=xcb" >> ~/.profile

and restart/logout

I am on Wayland and seeing the same result as @vineoak, is there a solution without having to swich to X11?

@jeroenvermunt, setting QT_QPA_PLATFORM=xcb when running OpenCV should launch under XWayland without requiring you to switch your session over to X11.

disable wayland in ubuntu system

go to /etc/gdm3/custom.conf and uncomment the “WaylandEnable=false”

Uncomment the line below to force the login screen to use Xorg WaylandEnable=false

then restart the PC

I tested out your provided wheel opencv_contrib_python-4.7.0.3564733-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl with wayland enabled environment and pyqt 5.15.8 installed on Ubuntu 22.04 and can confirm the same output as I now found on your PR #784. Hope this still helps.

qt.qpa.wayland: Failed to load client buffer integration: "wayland-egl"
qt.qpa.wayland: Available client buffer integrations: ()
qt.qpa.wayland: No shell integration named "xdg-shell" found
qt.qpa.wayland: No shell integration named "xdg-shell-v6" found
qt.qpa.wayland: No shell integration named "wl-shell" found
qt.qpa.wayland: No shell integration named "ivi-shell" found
qt.qpa.wayland: Loading shell integration failed.
qt.qpa.wayland: Attempted to load the following shells ("xdg-shell", "xdg-shell-v6", "wl-shell", "ivi-shell")

edit: I can also confirm that the wheel you built works nicely when I change the session to X11.