Here's a possible solution when you get the error Could not load the Qt platform plugin "xcb" in "…/python3.9/site-packages/cv2/qt/plugins" even though it was found.
The cause might be from a conflict between the Qt5 modules you've installed (with pyqt5-tools
for example) and the ones packaged with OpenCV.
The solution is to install a headless version of OpenCV: opencv-python-headless
or opencv-contrib-python-headless
.
BUT many times, OpenCV is installed as a dependecy of another library (the installer will not consider the "headless" version as a valid dependency). In my case it was Mediapipe.
The final solution is to trick the installer by using symbolic links. Here's the idea:
- (We install a headless version of OpenCV).
- We search for any folder named with "opencv_contrib_python_headless".
- We create a link to this folder and name it with "opencv_contrib_python".
- When installing the library (Mediapipe in my case) the installer will see the
To automate it on UNIX systems
environement=~/miniconda/envs/mediapipe # ADAPT IT TO YOU CASE
find $environement -name "opencv_contrib_python_headless*" | while read folder; do
headless_folder=${folder/_headless/}
test -e $headless_folder || ln -sv $folder $headless_folder
done
(On Windows, you will need to use the mklink /D Link Target
but I have no experience with it, sorry…)