Search code examples
pythonqmlpyinstallerqtquick2

QML Graphical Effects not working with PyInstaller


When I use PyInstaller 4.1 to bundle my PySide2 QML application. Any graphical effects do not get rendered. I have an example below with LinearGradient that does not work.

main.qml

import sys
import os

from PySide2.QtGui import QGuiApplication
from PySide2.QtQml import QQmlApplicationEngine


if __name__ == "__main__":
    app = QGuiApplication(sys.argv)
    engine = QQmlApplicationEngine()
    engine.load(os.path.join(os.path.dirname(__file__), "main.qml"))

    if not engine.rootObjects():
        sys.exit(-1)
    sys.exit(app.exec_())

main.py

import QtQuick 2.15
import QtQuick.Window 2.15
import QtGraphicalEffects 1.15

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")

    Item {
        width: 300
        height: 300

        LinearGradient {
            anchors.fill: parent
            start: Qt.point(0, 0)
            end: Qt.point(0, 300)
            gradient: Gradient {
                GradientStop { position: 0.0; color: "white" }
                GradientStop { position: 1.0; color: "black" }
            }
        }
    }
}

When I run this simple pyinstaller command it succeeds without any errors:

pyinstaller main.py

ubuntu@ubuntu:~/Projects/build_test$ pyinstaller main.py
22 INFO: PyInstaller: 4.1
22 INFO: Python: 3.7.3
23 INFO: Platform: Linux-5.0.0-23-generic-x86_64-with-Ubuntu-19.04-disco
23 INFO: wrote /home/ubuntu/Projects/build_test/main.spec
24 INFO: UPX is not available.
25 INFO: Extending PYTHONPATH with paths
['/home/ubuntu/Projects/build_test', '/home/ubuntu/Projects/build_test']
30 INFO: checking Analysis
30 INFO: Building Analysis because Analysis-00.toc is non existent
30 INFO: Initializing module dependency graph...
31 INFO: Caching module graph hooks...
35 INFO: Analyzing base_library.zip ...
1820 INFO: Caching module dependency graph...
1871 INFO: running Analysis Analysis-00.toc
1893 INFO: Analyzing /home/ubuntu/Projects/build_test/main.py
1937 INFO: Processing module hooks...
1937 INFO: Loading module hook 'hook-xml.py' from '/home/ubuntu/.local/lib/python3.7/site-packages/PyInstaller/hooks'...
2089 INFO: Loading module hook 'hook-PySide2.QtQml.py' from '/home/ubuntu/.local/lib/python3.7/site-packages/PyInstaller/hooks'...
2257 INFO: Loading module hook 'hook-encodings.py' from '/home/ubuntu/.local/lib/python3.7/site-packages/PyInstaller/hooks'...
2291 INFO: Loading module hook 'hook-difflib.py' from '/home/ubuntu/.local/lib/python3.7/site-packages/PyInstaller/hooks'...
2292 INFO: Excluding import of doctest from module difflib
2292 INFO: Loading module hook 'hook-PySide2.QtCore.py' from '/home/ubuntu/.local/lib/python3.7/site-packages/PyInstaller/hooks'...
2341 INFO: Loading module hook 'hook-PySide2.py' from '/home/ubuntu/.local/lib/python3.7/site-packages/PyInstaller/hooks'...
2356 INFO: Loading module hook 'hook-heapq.py' from '/home/ubuntu/.local/lib/python3.7/site-packages/PyInstaller/hooks'...
2357 INFO: Excluding import of doctest from module heapq
2357 INFO: Loading module hook 'hook-pickle.py' from '/home/ubuntu/.local/lib/python3.7/site-packages/PyInstaller/hooks'...
2358 INFO: Excluding import of argparse from module pickle
2358 INFO: Loading module hook 'hook-PySide2.QtNetwork.py' from '/home/ubuntu/.local/lib/python3.7/site-packages/PyInstaller/hooks'...
2407 INFO: Loading module hook 'hook-PySide2.QtGui.py' from '/home/ubuntu/.local/lib/python3.7/site-packages/PyInstaller/hooks'...
2476 INFO: Looking for ctypes DLLs
2476 INFO: Analyzing run-time hooks ...
2478 INFO: Including run-time hook '/home/ubuntu/.local/lib/python3.7/site-packages/PyInstaller/hooks/rthooks/pyi_rth_pyside2.py'
2481 INFO: Looking for dynamic libraries
7130 INFO: Looking for eggs
7131 INFO: Python library not in binary dependencies. Doing additional searching...
7190 INFO: Using Python library /usr/lib/x86_64-linux-gnu/libpython3.7m.so.1.0
7193 INFO: Warnings written to /home/ubuntu/Projects/build_test/build/main/warn-main.txt
7207 INFO: Graph cross-reference written to /home/ubuntu/Projects/build_test/build/main/xref-main.html
7248 INFO: checking PYZ
7248 INFO: Building PYZ because PYZ-00.toc is non existent
7248 INFO: Building PYZ (ZlibArchive) /home/ubuntu/Projects/build_test/build/main/PYZ-00.pyz
7476 INFO: Building PYZ (ZlibArchive) /home/ubuntu/Projects/build_test/build/main/PYZ-00.pyz completed successfully.
7477 INFO: checking PKG
7477 INFO: Building PKG because PKG-00.toc is non existent
7477 INFO: Building PKG (CArchive) PKG-00.pkg
7499 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
7500 INFO: Bootloader /home/ubuntu/.local/lib/python3.7/site-packages/PyInstaller/bootloader/Linux-64bit/run
7500 INFO: checking EXE
7500 INFO: Building EXE because EXE-00.toc is non existent
7500 INFO: Building EXE from EXE-00.toc
7500 INFO: Appending archive to ELF section in EXE /home/ubuntu/Projects/build_test/build/main/main
7504 INFO: Building EXE from EXE-00.toc completed successfully.
7507 INFO: checking COLLECT
7507 INFO: Building COLLECT because COLLECT-00.toc is non existent
7507 INFO: Building COLLECT COLLECT-00.toc
7967 INFO: Building COLLECT COLLECT-00.toc completed successfully.

Here is a list of all files and directories in /dist: https://pastebin.com/raw/2XMmi2yi

Here is the output after running the app with QT_DEBUG_PLUGINS=1: https://pastebin.com/raw/fHG1th1u

I've tried doing this on two different systems with the same result.


Solution

  • This issue has been resolved in PyInstaller. I submitted the bug and the developers fixed it.