无法使用cx_freeze和PySide2进行编译 [英] Unable to compile with cx_freeze and PySide2
问题描述
我有一个python程序正在尝试使用cx_freeze进行编译。我使用的GUI是PySide2。
I have a python program I'm trying to compile with cx_freeze. The GUI I'm using is PySide2.
我尝试过包含PySide2,这里不包括它,但我仍然遇到相同的错误。以下是我的setup.py代码
I've tried including PySide2, here is excluding it, but I keep getting the same error. Below is my setup.py code
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时,出现以下错误:
The program compiles fine, but when running the exe, I get the following error:
ModuleNotFoundError:没有名为'PySide2的模块'
"ModuleNotFoundError: No module named 'PySide2'"
推荐答案
所以错误是我已经用python 3.6安装了cx_freeze,但是所有我的软件包位于python 3.7文件夹中。我只是将其复制并粘贴到3.6文件夹中,然后稍稍更改了代码,该exe文件就可以很好地运行。
So the error was that I had installed cx_freeze with python 3.6, but all of my packages were in a python 3.7 folder. I simply copied and pasted into the 3.6 folder and changed the code a bit, and the exe works great.
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
)
T是个愚蠢的错误,但我变得更糟
T'was a dumb mistake, but I've made worse
这篇关于无法使用cx_freeze和PySide2进行编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!