Skip to content

Instantly share code, notes, and snippets.

@FrankwaP
Last active June 12, 2024 13:16
Show Gist options
  • Save FrankwaP/f45c9180cf85e5abe563d97f0af84ae5 to your computer and use it in GitHub Desktop.
Save FrankwaP/f45c9180cf85e5abe563d97f0af84ae5 to your computer and use it in GitHub Desktop.
Solution for `Could not load the Qt platform plugin "xcb"… even though it was found.`

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:

  1. (We install a headless version of OpenCV).
  2. We search for any folder named with "opencv_contrib_python_headless".
  3. We create a link to this folder and name it with "opencv_contrib_python".
  4. 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…)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment