gpt4 book ai didi

python - 无法使用 cx_freeze 和 PySide2 进行编译

转载 作者:行者123 更新时间:2023-12-01 00:43:56 28 4
gpt4 key购买 nike

我有一个 python 程序,正在尝试使用 cx_freeze 进行编译。我使用的 GUI 是 PySide2。

我尝试过包含 PySide2,这里排除它,但我不断收到相同的错误。下面是我的 setup.py 代码

from cx_Freeze import setup, Executable
import sys


includefiles = ['README.md', 'debug.log','tcl86t.dll', 'tk86t.dll', 'field.jpg', 'inputClass.py', 'mainfile.qml', 'MyTabView.qml', 'PlayerSelection.qml', 'selectedPlayers.py', 'Settings.qml', 'SimOutput.qml', 'simulationOutput.py']

includes = ["idna.idnadata", "atexit"]

excludes = ["PySide2"]

import os

os.environ['TCL_LIBRARY'] = r'C:\Users\pimat\AppData\Local\Programs\Python\Python36\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\pimat\AppData\Local\Programs\Python\Python36\tcl\tk8.6'


setup(name = "Simulation",
version = "0.2",
description = "Optimization Simulator",
options = {'build_exe':{'includes':includes,'excludes':excludes,'include_files':includefiles}},
executables = [Executable("main.py")])

程序编译正常,但运行 exe 时出现以下错误:

"ModuleNotFoundError: No module named 'PySide2'"

最佳答案

所以错误是我用 python 3.6 安装了 cx_freeze,但我的所有包都在 python 3.7 文件夹中。我只是复制并粘贴到 3.6 文件夹中并稍微更改了代码,exe 运行得很好。

from cx_Freeze import setup, Executable
import sys


# dependencies
build_exe_options = {
"packages": ["os", "sys", "re", "idna.idnadata", "atexit", "PySide2.QtCore", "PySide2.QtWidgets", "PySide2.QtUiTools", "PySide2.QtQuick", "PySide2.QtQml", "PySide2.QtGui", "shiboken2"],
"include_files": ['README.md', 'debug.log','tcl86t.dll', 'tk86t.dll', 'field.jpg', 'inputClass.py', 'mainfile.qml', 'MyTabView.qml', 'PlayerSelection.qml', 'selectedPlayers.py', 'Settings.qml', 'SimOutput.qml', 'simulationOutput.py',
],
"excludes": ["Tkinter", "Tkconstants", "tcl", ],
"build_exe": "build",
#"icon": "./example/Resources/Icons/monitor.ico"
}

executable = [
Executable("main.py",
base="Win32GUI",
targetName="Simulation.exe"
)
]



setup(name = "Simulation",
version = "0.2",
description = "Simulator",
options={"build_exe": build_exe_options},
executables=executable
)

这是一个愚蠢的错误,但我犯了更严重的错误

关于python - 无法使用 cx_freeze 和 PySide2 进行编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57135147/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com