Using PyQt5 with opencv-python (cv2) causes error "could not load Qt platform plugin xcb even though it was found"
-
@yashwant said in Using PyQt5 with opencv-python (cv2) causes error "could not load Qt platform plugin xcb even though it was found":
The problem arises only when I try to load python files with GUI.
That's the point. You may need to check how to make a Docker container use the GUI of the host...
wrote on 13 Apr 2021, 13:09 last edited by@Pablo-J-Rogina said in Using PyQt5 with opencv-python (cv2) causes error "could not load Qt platform plugin xcb even though it was found":
UI of the host..
Yes that was my goal (docker with gui)! and above mentioned was my error when I try GUI on docker.! Anyway thanks!
-
@Pablo-J-Rogina said in Using PyQt5 with opencv-python (cv2) causes error "could not load Qt platform plugin xcb even though it was found":
UI of the host..
Yes that was my goal (docker with gui)! and above mentioned was my error when I try GUI on docker.! Anyway thanks!
wrote on 13 Apr 2021, 13:24 last edited by@yashwant said in Using PyQt5 with opencv-python (cv2) causes error "could not load Qt platform plugin xcb even though it was found":
that was my goal (docker with gui)!
Yes, I understand that. Please take into account that this issue is not related (or produced by) Qt itself so the solution might come from some other source(s), not only this forum
-
wrote on 22 Apr 2021, 14:08 last edited by redeyed
@jeremy_k said in Using PyQt5 with opencv-python (cv2) causes error "could not load Qt platform plugin xcb even though it was found":
worka
Hello guys, so the problem is that
import cv2
setsQT_*
env vars.
I came to this workaround, maybe it will help someone:import cv2 for k, v in os.environ.items(): if k.startswith("QT_") and "cv2" in v: del os.environ[k]
-
wrote on 18 Sept 2021, 21:34 last edited by
I solved the problem by downgrading the cv2 version, simply run
python3 -m pip install opencv-contrib-python==4.1.0.25
i used to have the 4.5.3.56 -
Hey there,
I am working on a big project, creating a GUI for working with convolutional neural networks. I need to use cv2 for image processing. For some reason I cannot import cv2 without my application creating an error.
I am using pycharm as an IDE which is handling my virtual environment via pip. The librarys I use are the following:
- PyQt5
- pyqtchart
- pyyaml
- Pillow
- tensorflow
- distro
- numpy
- sklearn
- pandas
- opencv-python
When I use cv2 I get the following error-message:
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "$HOME/Documents/gui_nn/venv/lib/python3.8/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.
wrote on 18 Sept 2021, 21:37 last edited by -
wrote on 27 Oct 2021, 22:08 last edited by
@Hikari-Tretaki, muito obrigado por sua ajuda. Também consegui resolver o meu problema com sua dica.
-
@jeremy_k said in Using PyQt5 with opencv-python (cv2) causes error "could not load Qt platform plugin xcb even though it was found":
worka
Hello guys, so the problem is that
import cv2
setsQT_*
env vars.
I came to this workaround, maybe it will help someone:import cv2 for k, v in os.environ.items(): if k.startswith("QT_") and "cv2" in v: del os.environ[k]
wrote on 16 Mar 2022, 09:19 last edited by@redeyed Thankyou, I was confused around installing
opencv-python
and
opencv-python-headless
before this. But it ends with "we need both libraries, and this"
-
@lvlanson I had the same problem. You can install headless opencv without GUI. Then it works.
pip install opencv-python-headless
wrote on 15 May 2022, 03:07 last edited by@Hikari-Tretaki Thank you so much, installing opencv-python-headless fixed the issue
-
@lvlanson I had the same problem. You can install headless opencv without GUI. Then it works.
pip install opencv-python-headless
wrote on 18 Jul 2022, 09:55 last edited by@Hikari-Tretaki MAN, I LOVE YOU SO MUCH. THANKS!
-
wrote on 10 Oct 2022, 12:45 last edited by hitbuyi 10 Nov 2022, 01:39
I also have this problem, my environments are
1, OS: ubuntu20.04
2, conda: 4.13
3, PyQt5: 5.15.2
4, local Qt5: 5.15.6
5, opencv- python 4.5.xIt really takes several days to find a solution, @jeremy_k gave almost the solution. I use PyQt5 + OpenCV-python on conda virtual environment,
summarize the solutions :1, delete cv2/libqxcb.so, it works for pyqt5 which has its own version of Qt, but opencn-python doesn't work for other application which isn't relevant to PyQt5
2, if pyside2 is installed, pyside2 has its owen version of Qt, so add below code at the beginning of python program
``` import PySide2 dirname = os.path.dirname(PySide2.__file__) plugin_path = os.path.join(dirname, 'plugins', 'platforms') os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path ```
this solution works, at expense of intalling pyside2 which is 400M+
3, PyQt5 has its own version of Qt,similiar to above, add below code at the beginning of python program
``` import PyQt5 dirname = os.path.dirname(PyQt5.__file__) plugin_path = os.path.join(dirname, 'Qt5','plugins', 'platforms') os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path
this soltuion is fine,