opencv-python icon indicating copy to clipboard operation
opencv-python copied to clipboard

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

Open likehengqq opened this issue 1 year ago • 26 comments

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.)
  • [ ] I have read the README of this repository and understand that this repository provides only an automated build toolchain for OpenCV Python packages (there is no actual OpenCV code here)
  • [ ] The issue is related to the build scripts in this repository, to the pre-built binaries or is a feature request (such as "please enable this additional dependency")
  • [ ] I'm using the latest version of opencv-python

likehengqq avatar Sep 12 '22 16:09 likehengqq

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

KaranParekh11 avatar Sep 29 '22 12:09 KaranParekh11

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?

hitbuyi avatar Oct 10 '22 12:10 hitbuyi

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

You can try lowering the Python version.

likehengqq avatar Oct 17 '22 00:10 likehengqq

Hello guys,please I need help about this. I am getting same error here also and its not allowing video stream to continue.

qt.qpa.plugin: Could not find the Qt platform plugin "wayland" in "/home/bengab/venv/lib/python3.10/site-packages/cv2/qt/plugins

image

@likehengqq I have also tried decreasing the opencv-python version but its still not working.

bengabp avatar Oct 31 '22 23:10 bengabp

Guys the error shows but it still works. It shows like some kind of warning and it does not prevent my program from running. But when I use ffpyplayer to also read audio the error shows but this time it will not allow my program to run further.

Please what is the cause of this strange behavior?

bengabp avatar Nov 01 '22 12:11 bengabp

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.

asmorkalov avatar Nov 17 '22 07:11 asmorkalov

Hello guys,please I need help about this. I am getting same error here also and its not allowing video stream to continue.

qt.qpa.plugin: Could not find the Qt platform plugin "wayland" in "/home/bengab/venv/lib/python3.10/site-packages/cv2/qt/plugins

image

@likehengqq I have also tried decreasing the opencv-python version but its still not working.

yep similar issue here were you able to figure it out?

Viha123 avatar Jan 21 '23 02:01 Viha123

Related: https://stackoverflow.com/questions/68417682/qt-and-opencv-app-not-working-in-virtual-environment

asmorkalov avatar Jan 24 '23 09:01 asmorkalov

@likehengqq @bengabp @KaranParekh11 Could you try to install experimental package with Qr 5.15.8 and Wayland plugin enabled for build: https://github.com/opencv/opencv-python/actions/runs/4012888768? I need feedback from real Wayland-based system.

asmorkalov avatar Jan 26 '23 08:01 asmorkalov

https://github.com/opencv/opencv-python/pull/784

asmorkalov avatar Feb 03 '23 06:02 asmorkalov

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.

vineoak avatar Feb 16 '23 20:02 vineoak

Thanks. I got the same result with Kubuntu 22.04. It looks like I missed something in package.

asmorkalov avatar Feb 17 '23 06:02 asmorkalov

Is there any way to silence this message for now in the terminal?

mahyarmirrashed avatar Feb 21 '23 09:02 mahyarmirrashed

@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.

Petros626 avatar Feb 28 '23 21:02 Petros626

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

jeroenvermunt avatar Mar 26 '23 14:03 jeroenvermunt

Not yet for now.

asmorkalov avatar Mar 27 '23 06:03 asmorkalov

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

git-sparrowlinux avatar Sep 13 '23 08:09 git-sparrowlinux

  1. try sudo pip install opencv-python-headless

second option worked for me. thanks

MasterHM-ml avatar Sep 22 '23 16:09 MasterHM-ml

Same issue here, but the code itself is working fine. I've tried @ultimateagain steps and disabled this warning message.

Environment: OS: Ubuntu 22.04 Python: v3.10.12

MeqdadDev avatar Nov 10 '23 20:11 MeqdadDev

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.

jwillikers avatar Nov 10 '23 23:11 jwillikers

Try this:

import os
os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = "wayland"

rouftom avatar Nov 23 '23 00:11 rouftom

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

MasterHM-ml avatar Dec 07 '23 05:12 MasterHM-ml

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.

It works!

mak448a avatar Dec 20 '23 03:12 mak448a

A workaround I found was to use xwayland-run which spawns an xwayland instance for opencv to run in. I did it with QT_QPA_PLATFORM=xcb xwayland-run -- pipenv run python ... where pipenv installed opencv-python, opencv-contrib-python, and opencv-python-headless into a virtual environment

golfinq avatar Jan 01 '24 18:01 golfinq

Could be related, if not the exact same issue, since the problem is with bundled QT: https://bugreports.qt.io/browse/QTBUG-114635

Avasam avatar Jan 06 '24 20:01 Avasam

@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.

The problem is that opencv-python does not come with a library for Wayland so QT_QPA_PLATFORM_PLUGIN_PATH has no value and does not point to any location.

Therefore, your method does not solve the problem on systems operating based on Wayland such as Raspberry Pi-5.

$ ls .local/lib/python3.11/site-packages/opencv_python.libs
libavcodec-03bb4e36.so.59.37.100   libQt5Test-32fc1c2a.so.5.15.0      libxcb-icccm-05fb8c7f.so.4.0.0        libxcb-util-c74d156a.so.1.0.0
libavformat-1279b9be.so.59.27.100  libQt5Widgets-b1296c1e.so.5.15.0   libxcb-image-75825d2e.so.0.0.0        libxcb-xfixes-f4cf71d4.so.0.0.0
libavutil-f0a93969.so.57.28.100    libQt5XcbQpa-7b9d0389.so.5.15.0    libxcb-keysyms-73cd270d.so.1.0.0      libxcb-xinerama-6372573d.so.0.0.0
libcrypto-956af892.so.1.1          libssl-b9692d76.so.1.1             libxcb-randr-e1606dfc.so.0.1.0        libxcb-xkb-e2f6f9de.so.1.0.0
libgfortran-8634ef04.so.3.0.0      libswresample-39e38dfb.so.4.7.100  libxcb-render-76b15fe5.so.0.0.0       libxkbcommon-e272a37d.so.0.0.0
libopenblas-r0-8966572e.3.3.so     libswscale-86dc6859.so.6.7.100     libxcb-render-util-486ef3ee.so.0.0.0  libxkbcommon-x11-b76c7d31.so.0.0.0
libpng16-45e47e2f.so.16.40.0       libvpx-b07bc8cf.so.8.0.1           libxcb-shape-e8fe4bc4.so.0.0.0
libQt5Core-9e162752.so.5.15.0      libX11-xcb-8ab4be54.so.1.0.0       libxcb-shm-cad72500.so.0.0.0
libQt5Gui-08f6a1f3.so.5.15.0       libXau-21870672.so.6.0.0           libxcb-sync-dc271c48.so.1.0.0

There is no Wayland library.

RUN curl -C - -O -L https://download.qt.io/official_releases/qt/5.15/${QT_VERSION}/single/qt-everywhere-src-${QT_VERSION}.tar.xz && \
    tar -xf qt-everywhere-src-${QT_VERSION}.tar.xz && \
    cd qt-everywhere-src-${QT_VERSION} && \
    export MAKEFLAGS=-j$(nproc) && \
    ./configure -prefix /opt/Qt${QT_VERSION} -release -opensource -confirm-license -qtnamespace QtOpenCVPython -xcb -xcb-xlib -bundled-xcb-xinput -no-openssl -no-dbus -skip qt3d -skip qtactiveqt -skip qtcanvas3d -skip qtconnectivity -skip qtdatavis3d -skip qtdoc -skip qtgamepad -skip qtgraphicaleffects -skip qtimageformats -skip qtlocation -skip qtmultimedia -skip qtpurchasing -skip qtqa -skip qtremoteobjects -skip qtrepotools -skip qtscript -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtspeech -skip translations \
 -skip qtwayland \
-skip qtwebchannel -skip qtwebengine -skip qtwebsockets -skip qtwebview -skip xmlpatterns -skip declarative -make libs && \
    make && \
    make install && \
    cd .. && \
    rm -rf qt-everywhere*

The deeper cause lies in the Dockerfile build operation, which ignored the Wayland build "-skip qtwayland"

EnziinSystem avatar May 18 '24 08:05 EnziinSystem