Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
具有qml的PyQt5可执行应用程序_Qml_Exe_Cx Freeze_Pyqt5 - Fatal编程技术网

具有qml的PyQt5可执行应用程序

具有qml的PyQt5可执行应用程序,qml,exe,cx-freeze,pyqt5,Qml,Exe,Cx Freeze,Pyqt5,我试图通过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.

我试图通过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'
 }

我找到了一个答案,我应该在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上自动处理了。