I'm having trouble generating an exe using Pyinstaller. My biggest problem should be "including the qml file". I tried a lot, but still failed. Hope someone can show me how the spec file should be written in order to include the QML.
Generally, what I want, is to create a Windows Exe from my Pyside+QML Application. But how?
main.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtDeclarative import QDeclarativeView
# Create Qt application and the QDeclarative view
app = QApplication(sys.argv)
view = QDeclarativeView()
# Create an URL to the QML file
url = QUrl('view.qml')
# Set the QML file and show
view.setSource(url)
view.setResizeMode(QDeclarativeView.SizeRootObjectToView)
view.show()
# Enter Qt main loop
sys.exit(app.exec_())
view.qml
import QtQuick 1.0
Rectangle {
width: 200
height: 200
color: "red"
Text {
text: "Hello World"
anchors.centerIn: parent
}
}
Not sure about PySide, but PyInstaller as of 2.1 supports PyQt5. I'd assume that the general procedure is similar.
For PyQt5 put your qml files into a resource file, which you then compile using pyrcc5 (pyside-rcc). You then import the generated python module and PyInstaller will treat it like any other module.
It is also possible to include the qml files directly. By doing something like this:
extrafiles = [('myfile.qml', os.path.join('path', 'to', 'myfile.qml'), 'DATA')]
...
coll = COLLECT( exe,
a.binaries + extralibs,
a.zipfiles,
a.datas + extrafiles,
...
You will probably also need to package the qml libraries from the qml dir returned by qmake -query QT_INSTALL_QML
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With