简体   繁体   English

无法使用 cx_freeze 和 PySide2 进行编译

[英]Unable to compile with cx_freeze and PySide2

I have a python program I'm trying to compile with cx_freeze.我有一个试图用 cx_freeze 编译的 python 程序。 The GUI I'm using is PySide2.我使用的 GUI 是 PySide2。

I've tried including PySide2, here is excluding it, but I keep getting the same error.我试过包括 PySide2,这里不包括它,但我一直收到同样的错误。 Below is my setup.py code下面是我的 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")])

The program compiles fine, but when running the exe, I get the following error:程序编译正常,但是在运行 exe 时,出现以下错误:

"ModuleNotFoundError: No module named 'PySide2'" “ModuleNotFoundError:没有名为‘PySide2’的模块”

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.所以错误是我用 python 3.6 安装了 cx_freeze,但我所有的包都在 python 3.7 文件夹中。 I simply copied and pasted into the 3.6 folder and changed the code a bit, and the exe works great.我只是简单地复制并粘贴到 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
      )

T'was a dumb mistake, but I've made worse这是一个愚蠢的错误,但我做得更糟

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM