当用pyinstaller导出python程序时,如何正确地排除故障?

2024-04-24 15:00:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我最近创建了一个Python程序,并使用PyInstaller将其打包到一个exe中

问题是它产生的exe生成的窗口消失得太快了,我无法读取其中的内容

我找不到办法让窗户开着:

-c-wPyIinstaller命令不起作用,也不起作用--debug all:窗口仍在出现,在其中生成超快速的终端文本,然后关闭自己,没有给我足够的时间来读取它遇到的问题

有没有一种方法可以让PyInstaller-ex生成一个日志文件,记录我运行它们时发生的事情? 你有什么其他的建议,我可以做什么来理解为什么我的程序崩溃,或保持它的窗口打开,以便我可以阅读它是什么? 感谢您的关注:)


Tags: 方法debug文本命令程序终端内容时间
1条回答
网友
1楼 · 发布于 2024-04-24 15:00:57

对代码进行故障排除与Pyinstaller无关。您可以使用pythonlogging并将控制台输出重定向到文本文件。在here中有一个很好的例子

另外,根据this,如果您在导入模块时遇到问题并且需要更多信息,您可以使用详细模式-v标记来打印有关Pyinstaller导入模块状态的更多信息

You can also pass a -v (verbose imports) flag to the embedded Python interpreter (see Giving Run-time Python Options above). This can be extremely useful. It can be informative even with apps that are apparently working, to make sure that they are getting all imports from the bundle, and not leaking out to the local installed Python.

对于最后一个问题,如果您需要使用JSON字符串,您可以使用Python的dictionary类型,然后使用json模块(json.dumps)将dict转换为有效的JSON字符串。您可以在here中找到更多信息

相关问题 更多 >