【问题标题】:PyQt5 executable application with qml带有 qml 的 PyQt5 可执行应用程序
【发布时间】:2014-07-17 03:59:05
【问题描述】:

我正在尝试通过 cx_Freeze 构建一个简单的可执行 PyQt5 应用程序,但是当我启动构建的 exe 文件时,它告诉我一个错误,找不到 qml 文件

main.py

from PyQt5.QtNetwork import *
from PyQt5.QtQml import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *

class MainWin(object):
    def __init__(self):
        self.eng = QQmlApplicationEngine()
        self.eng.load('main.qml')
        win = self.eng.rootObjects()[0]
        win.show()

if __name__ == '__main__':
    import sys
    App = QApplication(sys.argv)
    Win = MainWin()
    sys.exit(App.exec_())

main.qml

import QtQuick 2.2
import QtQuick.Controls 1.0
ApplicationWindow {
    id: main
    width: 400
    height: 600
    color: 'grey'
 }

【问题讨论】:

    标签: qml exe cx-freeze pyqt5


    【解决方案1】:

    我找到了答案,我应该在 cx_freeze setup.py 中包含 qtquick,如下所示:

    if sys.platform == "win32":
        base = "Win32GUI"
        PYQT5_DIR = "d:/programs/Python3/lib/site-packages/PyQt5"
        include_files = [
            "qml/",
            (os.path.join(PYQT5_DIR, "qml", "QtQuick.2"), "QtQuick.2"),
            (os.path.join(PYQT5_DIR, "qml", "QtQuick"), "QtQuick"),
            (os.path.join(PYQT5_DIR, "qml", "QtGraphicalEffects"), "QtGraphicalEffects"),
        ]
    
    setup(
        name="exe",
        version="0.9",
        description="asd",
        author="beast",
        author_email="houshao55@gmail.com",
        options={"build_exe": {"includes": ["atexit",     "sip","PyQt5.QtCore","PyQt5.QtGui","PyQt5.QtWidgets",
                                        "PyQt5.QtNetwork","PyQt5.QtOpenGL", "PyQt5.QtQml", "PyQt5.QtQuick"],
                           "include_files": include_files,
                           "excludes" : ['Tkinter'],
                           # "optimize" : 2,
                           # "compressed" : True,
                           # "include_msvcr" : True,
                       }},
    executables=[
        Executable(script="main.py",
                   targetName="EVTicket.exe",
                   base=base)
    ]
    )
    

    【讨论】:

    • 谢谢,我已经在 cx_Freeze 上 made an issue 自动处理这个问题。
    猜你喜欢
    • 2022-01-21
    • 1970-01-01
    • 2019-08-12
    • 1970-01-01
    • 1970-01-01
    • 2017-06-19
    • 1970-01-01
    • 2015-10-12
    • 1970-01-01
    相关资源
    最近更新 更多