cx_freeze调试控制台?

cx_freeze debugging console?

我尝试将我的(正常工作)python 3.6 tkinter gui 应用构建为 windows 可执行文件。经过几个小时的尝试,出现了一个错误(有一些名称和 dll 问题),我得到了 运行。但它似乎有各种各样的错误。有些功能似乎不起作用,而且我没有生成错误的控制台输出...是否有调试 exe 的方法?

这是我的setup.py

import sys
from cx_Freeze import setup, Executable
import os

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

base = None
if sys.platform == 'win32':
    base = 'Win32GUI'

executables = [
    Executable('myApp.py', base=base)
]

build_exe_options = {"packages": ["tkinter",
                                  "PIL",
                                  "savReaderWriter",
                                  "numpy",
                                  "scipy",
                                  "os"],
                     "include_files": ["tcl86t.dll",
                                       "tk86t.dll"]}

setup(name='myApp',
      version='0.1',
      description='some description',
      options = {'build_exe': build_exe_options},
      executables=executables
      )

myApp.py

太大了 post 放在这里。这是一个仅适用于 'unfreezed' 的片段。您需要一个 spss.sav 文件 like this 来尝试这个。

from tkinter import *
from tkinter import ttk, filedialog, messagebox
from PIL import Image, ImageTk, ImageDraw
from savReaderWriter import SavReader
import numpy as np
from scipy.ndimage import gaussian_filter
import os

class MyApp:

    spss_file = None

    def import_spss(self, *args):

        filename = filedialog.askopenfilename()

        if filename:
            try:
                with SavReader(filename, returnHeader=True, ioUtf8=True) as reader:
                    spss_file = reader.all()

                self.spss_file = np.array(spss_file)

            except Exception as ex:
                messagebox.showinfo(title="Import SPSS File",
                                    message="Warning: wrong file format chosen! \nAccepted formats: sav")
                print(ex)
                return
        else:
            return


def main():
    App = MyApp()
    App.import_spss()
    print("everything works fine")

main()

如果您希望控制台 window 出现,在它被冻结后,只需从设置脚本中删除此代码:

if sys.platform == 'win32':
    base = 'Win32GUI'

该代码的作用是告诉 cx_Freeze 在冻结后让控制台 window 出现。这仅在 windows 上是必需的,因为在其他操作系统上,它取决于它是否来自终端 运行。不过,请确保在完成调试后将代码放回原处,否则控制台 window 显示在您的应用程序中。
顺便说一句,我曾经遇到过的最烦人的问题之一是在使用 tkintercx_Freeze 编写程序时。问题是它在错误的目录中启动,无法找到 TK Dll。如果当您 运行 使用控制台执行此操作时,您看到有关未找到文件的信息,很可能是您没有包含它或它位于错误的目录中。
祝你有美好的一天!