Ubuntu 22.04/24.04 PyQt5 designer installation / execution (xcb error) in anaconda

As I tried to install PyQt5 and designer, 

I got many error to execute pyqt UI on ubuntu machine. 

Many people told me to upgrade pyqt5 to pyqt6 but. I have to proceed my project with pyqt5. 

So, I found follow scripts one by one. 

I've double-checked on fresh installed ubuntu machine one by one. So you can follow my instructions. 


0. install anaconda3

1. create env using conda

$> conda create -n [envname] python==3.11

$> conda activate envname

2. Install pyqt5 and designer

(envname)$> pip install pyqt5

(envname)$> sudo apt-get update && sudo apt-get upgrade

(envname)$> sudo apt-get install qt5-default  

#Cannot find qt5-default after version ubuntu 20.04. so, you can install followings for qt5-default features 

(envname)$> sudo apt-get install qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools

(envname)$> sudo apt-get install qttools5-dev-tools


Now you can run designer to make pyqt5 UI. 


3. then you can install python libraries using pip. 


(envname)$> pip install matplotlib opencv-python-headless ...


Then run vscode using command 'code .' and run the python script.


4. xcb error handling


A pyqt application got an error message like this:

'qt.qpa.plugin: Could not load the Qt platform plugin "wayland" in "/home/[username]/.conda/envs/[envname]/lib/python3.11/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.'


opencv makes crashes with ubuntu's library. 

So, that's why I install opencv-python-headless not opencv-python

So, follow instructions. 


Temporarily move libqxcb.so for avoid library collision.

mv ~/.conda/envs/envname/lib/python3.11/site-package/cv2/qt/plugins/platform/libqxcb.so ~/Downloads


5. MESA-LOADER error handling


Even it doesn't work with different error. Black UI box of Qt5 UI showed up with libGL, MESA error messages. 



(envname)$> cd /home/$USER/.conda/envs/[envname]/lib

(envname)$> mkdir backup  

                           # Create a new folder to keep the original libstdc++

(envname)$> mv libstd* backup  

                           # Put all libstdc++ files into the folder, including soft links

(envname)$> cp /usr/lib/x86_64-linux-gnu/libstdc++.so.6  ./ 

                          # Copy the c++ dynamic link library of the system here

(envname)$> ln -s libstdc++.so.6 libstdc++.so

(envname)$> ln -s libstdc++.so.6 libstdc++.so.6.0.19


(envname)$> conda install -c conda-forge libstdcxx-ng

(envname)$> export QT_QPA_PLATFORM=xcb 


Run the code again, then it works like a charm. 







BTW, in case of adding last export script to .bashrc, you can add it using nano or vi. 


$> vi ~/.bashrc

add 'export QT_QPA_PLATFORM=xcb' at end of script







Comments