Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy PyQt5 application on different Linux machine

I'm struggling with this problem since a week now so I guess it's time to ask for some help. Long story short: I'm building an application using Python 3.4 and PyQt5 and I'm using cx_Freeze to create a standalone executable of my application. While on Windows and Mac OS everything goes fine I encountered this problem while executing my frozen application on a Ubuntu operating system on which Qt5 is not installed:

This application failed to start because it could not find or load the Qt platform plugin "xcb".

Available platform plugins are: linuxfb, minimal, offscreen, xcb.

The application runs fine on the machine I'm using to build the frozen package (where Qt5 is installed).

I have googled a bit and it seems that this problem is quite common. I tried everything I could find in the following links:

  • "Failed to load platform plugin "xcb" " while launching qt5 app on linux without qt installed
  • (Qt 5.4.1) This application failed to start because it could not find or load the Qt platform plugin "xcb"

In the frozen application I do have the platforms directory in which there is libqxcb.so. Just for consistency I'm posting the output of the ldd libqxcb.so which is the same on both the machines where Qt5 is installed, and the other one I'm using for testing where I only have a fresh Ubuntu 14.04 install (no Qt5):

linux-vdso.so.1 =>  (0x00007fff563a3000)
libQt5XcbQpa.so.5 => not found
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007feddfeee000)
libX11-xcb.so.1 => /usr/lib/x86_64-linux-gnu/libX11-xcb.so.1 (0x00007feddfcec000)
libXi.so.6 => /usr/lib/x86_64-linux-gnu/libXi.so.6 (0x00007feddfadc000)
libSM.so.6 => /usr/lib/x86_64-linux-gnu/libSM.so.6 (0x00007feddf8d4000)
libICE.so.6 => /usr/lib/x86_64-linux-gnu/libICE.so.6 (0x00007feddf6b8000)
libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007feddf499000)
libfontconfig.so.1 => /usr/lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007feddf25d000)
libfreetype.so.6 => /usr/lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007feddefba000)
libQt5DBus.so.5 => /usr/lib/x86_64-linux-gnu/libQt5DBus.so.5 (0x00007fedded3b000)
libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007feddeb39000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fedde931000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007fedde629000)
libXrender.so.1 => /usr/lib/x86_64-linux-gnu/libXrender.so.1 (0x00007fedde41f000)
libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007fedde20d000)
libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007feddded8000)
libQt5Gui.so.5 => /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5 (0x00007feddd88b000)
libQt5Core.so.5 => /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 (0x00007feddd1e5000)
libGL.so.1 => /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1 (0x00007feddcf53000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007feddcd35000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007feddca31000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007feddc72b000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007feddc515000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007feddc150000)
/lib64/ld-linux-x86-64.so.2 (0x00007fede02f4000)
libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007feddbf4b000)
libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007feddbd47000)
libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007feddbb41000)
libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007feddb917000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007feddb6fe000)
libpng12.so.0 => /lib/x86_64-linux-gnu/libpng12.so.0 (0x00007feddb4d8000)
libdbus-1.so.3 => /lib/x86_64-linux-gnu/libdbus-1.so.3 (0x00007feddb293000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007feddb055000)
libharfbuzz.so.0 => /usr/lib/x86_64-linux-gnu/libharfbuzz.so.0 (0x00007feddae00000)
libicui18n.so.52 => /usr/lib/x86_64-linux-gnu/libicui18n.so.52 (0x00007fedda9f9000)
libicuuc.so.52 => /usr/lib/x86_64-linux-gnu/libicuuc.so.52 (0x00007fedda680000)
libglapi.so.0 => /usr/lib/x86_64-linux-gnu/libglapi.so.0 (0x00007fedda456000)
libXdamage.so.1 => /usr/lib/x86_64-linux-gnu/libXdamage.so.1 (0x00007fedda253000)
libXfixes.so.3 => /usr/lib/x86_64-linux-gnu/libXfixes.so.3 (0x00007fedda04d000)
libxcb-glx.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-glx.so.0 (0x00007fedd9e36000)
libxcb-dri2.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-dri2.so.0 (0x00007fedd9c31000)
libxcb-dri3.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-dri3.so.0 (0x00007fedd9a2e000)
libxcb-present.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-present.so.0 (0x00007fedd982b000)
libxcb-sync.so.1 => /usr/lib/x86_64-linux-gnu/libxcb-sync.so.1 (0x00007fedd9625000)
libxshmfence.so.1 => /usr/lib/x86_64-linux-gnu/libxshmfence.so.1 (0x00007fedd9423000)
libXxf86vm.so.1 => /usr/lib/x86_64-linux-gnu/libXxf86vm.so.1 (0x00007fedd921d000)
libdrm.so.2 => /usr/lib/x86_64-linux-gnu/libdrm.so.2 (0x00007fedd9011000)
libgraphite2.so.3 => /usr/lib/x86_64-linux-gnu/libgraphite2.so.3 (0x00007fedd8df5000)
libicudata.so.52 => /usr/lib/x86_64-linux-gnu/libicudata.so.52 (0x00007fedd7588000)

The same applies to ldd Eddy (where Eddy is the application executable name):

linux-vdso.so.1 =>  (0x00007fffc812e000)
libpython3.4m.so.1.0 => /home/daniele/Desktop/eddy/build/Eddy-0.4-gpl-linux64/./libpython3.4m.so.1.0 (0x00007fab72345000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fab72127000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fab71d62000)
libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007fab71b38000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fab7191f000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fab7171b000)
libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007fab71518000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fab71212000)
/lib64/ld-linux-x86-64.so.2 (0x00007fab7297a000)

On the machine where I'm creating the frozen application I tried both Qt5 compiled from source and Qt5 installed using the offline installer. I used SIP 4.17 and PyQt5 5.5.1 compiled from sources and cx_Freeze 3.4.3.

Any advice?

EDIT1: I already tried moving libQt5XcbQpa.so.5 (along with libQt5QCore.so.5, etc..) into my build directory but it didn't help.

like image 795
Daniele Pantaleone Avatar asked Oct 30 '22 13:10

Daniele Pantaleone


1 Answers

Copying the library files to the build directory is not enough for Linux targets. Make sure the directory is in your $LD_LIBRARY_PATH.

These instructions taken from the QT Deployment documentation might help:

Unless told otherwise, the dynamic linker doesn't search the directory where your application resides. There are many ways to solve this:

  • You can install the Qt libraries in one of the system library paths (e.g. /usr/lib on most systems).
  • You can pass a predetermined path to the -rpath command-line option when linking the application. This will tell the dynamic linker to look in this > directory when starting your application.
  • You can write a startup script for your application, where you modify the dynamic linker configuration (e.g., adding your application's directory to the LD_LIBRARY_PATH environment variable.

Note: If your application will be running with "Set user ID on execution," and if it will be owned by root, then LD_LIBRARY_PATH will be ignored on some platforms. In this case, use of the LD_LIBRARY_PATH approach is not an option).

like image 141
ozgun Avatar answered Nov 02 '22 02:11

ozgun