mherrmann / fbs

Create Python GUIs with Qt in minutes
https://build-system.fman.io
GNU General Public License v3.0
3.8k stars 194 forks source link

Linux builds require rebuilding ZLIB #185

Open PhilippVerpoort opened 4 years ago

PhilippVerpoort commented 4 years ago

I ran into some trouble while trying to build my PyQT5 application for Ubuntu using the VM. After building and running the VM, and then fbs freezeing and fbs releaseing the Debian package, the applications crashes with the following error:

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

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.

Reinstalling the application may fix this problem.
Aborted

So I inspected this error a bit more carefully by setting export QT_DEBUG_PLUGINS=1. I then got the following output:

Got keys from plugin meta data ("xcb")
QFactoryLoader::QFactoryLoader() checking directory path "/opt/Table-Allocations-Manager/platforms" ...
Cannot load library /opt/Table-Allocations-Manager/PyQt5/Qt/plugins/platforms/libqxcb.so: (/opt/Table-Allocations-Manager/libz.so.1: version `ZLIB_1.2.9' not found (required by /usr/lib/x86_64-linux-gnu/libpng16.so.16))
QLibraryPrivate::loadPlugin failed on "/opt/Table-Allocations-Manager/PyQt5/Qt/plugins/platforms/libqxcb.so" : "Cannot load library /opt/Table-Allocations-Manager/PyQt5/Qt/plugins/platforms/libqxcb.so: (/opt/Table-Allocations-Manager/libz.so.1: version `ZLIB_1.2.9' not found (required by /usr/lib/x86_64-linux-gnu/libpng16.so.16))"
This application failed to start because it could not find or load the Qt platform plugin "xcb"
in "".

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.

Reinstalling the application may fix this problem.
Aborted

So apparently there's a problem with the version of ZLIB that the Debian package installs. I was able to resolve this by building ZLIB_1.2.9 manually on the VM before running freeze and release. I found the following instructions here and downloaded ZLIB_1.2.9 from here, and all that worked well:

tar -xvf ~/Downloads/zlib-1.2.9.tar.gz
cd zlib-1.2.9
sudo -s
./configure; make; make install
cd /lib/x86_64-linux-gnu
ln -s -f /usr/local/lib/libz.so.1.2.9/lib libz.so.1
cd ~
rm -rf zlib-1.2.9

Perhaps a way could be found to prevent this from happening in the future? Maybe just update the ZLIB dependency for the Docker VM?

mherrmann commented 4 years ago

Couldn't the problem also be that your system apparently tries to load /usr/lib/x86_64-linux-gnu/libpng16.so.16? Maybe it can be fixed by copying libpng16.so.16 from the VM into the target/ directory.

PhilippVerpoort commented 4 years ago

Hi Michael!

No, I don't think that's the problem. libpng16.so.16 already is in the target/ directory, and the error message tells me that it found libpng16.so.16 but not ZLIB_1.9, which is a dependency of libpng16.so.16. Also I wasn't able to locate the libpng16.so.16 file anywhere on the VM.

Does that make sense? I can try further things if that helps!

mherrmann commented 4 years ago

Your output contains /usr/lib/x86_64-linux-gnu/libpng16.so.16. I think this should not be there if you have libpng16.so.16 in our app directory. (Then, the path should be /opt/YourApp/libpng16.so.16.) In my eyes, the root cause of the problem is that /usr/lib/x86_64-linux-gnu/libpng16.so.16 is being loaded at all.

josh-richardson commented 4 years ago

I can confirm that I'm experiencing exactly the same issue attempting to run the artifacts generated by fbs freeze (themselves generated from within fbs runvm on a fresh new project) on the host system (Arch Linux). I haven't looked into this in detail, but was able to fix it by following the steps detailed by Philipp.

meramsey commented 4 years ago

I can also confirm this same issue

Traceback (most recent call last):
  File "python/main.py", line 32, in <module>
  File "/root/WizardAssistant/venv/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
  File "wizardwebssh/tabbedterminal.py", line 9, in <module>
ImportError: /opt/WizardAssistant/libz.so.1: version `ZLIB_1.2.9' not found (required by /usr/lib/x86_64-linux-gnu/libpng16.so.16)
[30817] Failed to execute script main

Copying the file manually there ends up continuing to cause more issues

[14066:14099:0522/120015.167819:ERROR:gl_implementation.cc(225)] Failed to load libGL.so.1: /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0: undefined symbol: g_build_filename_valist [14066:14099:0522/120015.428585:ERROR:gl_surface_qt.cpp(667)] Requested OpenGL implementation is not supported. Implementation: 0 Segmentation fault (core dumped)

Switching from QT_WEBENGINE_DISABLE_GPU=0

to QT_WEBENGINE_DISABLE_GPU=1

Also results in either no errors if outside env or the below

Copying all the same files from working one built on Ubuntu 18.04/Mint Linux not in the docker causes more issues.

image

goes from this to nothing If i toggle that mode.

Theres numerous other threads about this on ubuntu forums and stack overflow. https://stackoverflow.com/questions/48306849/lib-x86-64-linux-gnu-libz-so-1-version-zlib-1-2-9-not-found

Also referenced here same error https://github.com/DFRobot/uPyCraft/issues/16

Looks like this version jumps from libz.so.1.2.8 > libz.so.1.2.11 when going from 16.x to 18. 19.x etc zlib1g

https://packages.ubuntu.com/xenial/amd64/zlib1g/filelist

File list of package zlib1g in xenial of architecture amd64

/lib/x86_64-linux-gnu/libz.so.1 /lib/x86_64-linux-gnu/libz.so.1.2.8 /usr/share/doc/zlib1g/changelog.Debian.gz /usr/share/doc/zlib1g/copyright

From docker Ubuntu 16.04 apt-file search libz.so.1

(venv) ubuntu:WizardAssistant$ apt-file search libz.so.1
lib32z1: /usr/lib32/libz.so.1
lib32z1: /usr/lib32/libz.so.1.2.8
libx32z1: /usr/libx32/libz.so.1
libx32z1: /usr/libx32/libz.so.1.2.8
libzadc1: /lib/x86_64-linux-gnu/genwqe/libz.so.1
zlib1g: /lib/x86_64-linux-gnu/libz.so.1
zlib1g: /lib/x86_64-linux-gnu/libz.so.1.2.8
(venv) ubuntu:WizardAssistant$ 

https://packages.ubuntu.com/bionic/amd64/zlib1g/filelist

File list of package zlib1g in bionic of architecture amd64

/lib/x86_64-linux-gnu/libz.so.1 /lib/x86_64-linux-gnu/libz.so.1.2.11 /usr/share/doc/zlib1g/changelog.Debian.gz /usr/share/doc/zlib1g/copyright

From host OS Ubuntu 18.04

 apt-file search libz.so.1
lib32z1: /usr/lib32/libz.so.1
lib32z1: /usr/lib32/libz.so.1.2.11
lib32z1: /usr/lib32/libz.so.1.2.8
libx32z1: /usr/libx32/libz.so.1
libx32z1: /usr/libx32/libz.so.1.2.11
libx32z1: /usr/libx32/libz.so.1.2.8
libzadc1: /lib/x86_64-linux-gnu/genwqe/libz.so.1
libzadc4: /usr/lib/x86_64-linux-gnu/genwqe/libz.so.1
zlib1g: /lib/x86_64-linux-gnu/libz.so.1
zlib1g: /lib/x86_64-linux-gnu/libz.so.1.2.11
zlib1g: /lib/x86_64-linux-gnu/libz.so.1.2.8
meramsey commented 4 years ago

I ended up getting mine to work by just adding the version of libz.so.1 that worked from the Ubuntu 18.04 debian installer when i did fbs freeze. It ended up not being the same one as i thought it was when i had manually tried to copy it before from the live OS. project/src/main/resources/ubuntu/libz.so.1

Its attached in case anyone wants it. libz.so.1.zip

It now compiles on Ubuntu 16.x docker and loads for all Ubuntu versions I have tried.

I also solved the unrelated problem with the "Failed to load libGL.so.1" with the below in case anyone sees this and wondering how I fixed it.

super old bug that Nvidia and PyQt never fully fixed mostly Nvidia's fault though :/ Stupid details: https://bugs.launchpad.net/ubuntu/+source/python-qt4/+bug/941826 https://github.com/spyder-ide/spyder/issues/3226 https://github.com/Ultimaker/Cura/pull/131 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=913287 https://bugreports.qt.io/browse/QTBUG-71488

What I did to fix this added almost to the top of the main file.


if distro.like() == 'ubuntu':
    print('Importing ctypes')
    # This import is needed to fix errors with Nvidia Drivers on Ubuntu/Debian QtWebEngine: can load wrong libGL.so
    # See issue 3332
    try:
        # from OpenGL import GL
        import ctypes
        from ctypes import util
        ctypes.CDLL(ctypes.util.find_library("GL"), mode=ctypes.RTLD_GLOBAL)
        ctypes.CDLL(ctypes.util.find_library("gcc_s"), mode=ctypes.RTLD_GLOBAL)
       # fixes libz by loading the one from src/main/resources/ubuntu/libz.so.1
        ctypes.CDLL('libz.so.1', ctypes.RTLD_GLOBAL)
        print('Imported ctypes successfully')
    except:
        print('ctypes NOT imported')
        pass