Python Pyinstaller窗口化问题

Python Pyinstaller窗口化问题,python,pyqt,subprocess,exe,pyinstaller,Python,Pyqt,Subprocess,Exe,Pyinstaller,我目前在pyinstaller 3.5中遇到了一个问题,我使用Pyqt和子进程编写了一个脚本,并使用pyinstaller将其打包成一个.exe。如果我在没有参数--windowsed的情况下打包.exe,脚本可以正常工作。一旦我通过——作为参数打开窗口,一切都不起作用。调试已经不可能了,因为我没有输出。有人知道这个错误是否有意义吗?可能需要更多信息来发现问题 一, 使用pyinstaller+子流程时,需要注意以下几点。 我建议,要点如下: 当使用--noconsole选项从Pyinstall

我目前在pyinstaller 3.5中遇到了一个问题,我使用Pyqt和子进程编写了一个脚本,并使用pyinstaller将其打包成一个.exe。如果我在没有参数--windowsed的情况下打包.exe,脚本可以正常工作。一旦我通过——作为参数打开窗口,一切都不起作用。调试已经不可能了,因为我没有输出。有人知道这个错误是否有意义吗?

可能需要更多信息来发现问题

一,

使用
pyinstaller+子流程时,需要注意以下几点。
我建议,要点如下:

当使用--noconsole选项从Pyinstaller运行时,默认情况下,subprocess.Popen将弹出一个命令窗口

默认情况下,Windows不会搜索路径

使用--noconsole选项从Pyinstaller生成的二进制文件运行此命令需要重定向所有内容(stdin、stdout、stderr),以避免出现OSError异常:“[Error 6]句柄无效。”

二,

然后,出于调试目的,您可以尝试使用调试选项(doc is)运行pyinstaller:

pyinstaller--debug=all

这可以为你指明正确的方向

三,

最后,一些
sys.stdout
代码还可以阻止
exe
窗口模式下运行,例如:

sys.stdout.reconfigure(encoding='utf-8')
#or
sys.stdout = open(sys.stdout.fileno(), mode='w', encoding='utf8', buffering=1)
在这种情况下,使用以下代码更改
sys.stdout
编码可能会有所帮助:

if sys.stdout.encoding != 'UTF-8':
    sys.stdout = codecs.getwriter('utf-8')(sys.stdout.buffer, 'strict')
if sys.stderr.encoding != 'UTF-8':
    sys.stderr = codecs.getwriter('utf-8')(sys.stderr.buffer, 'strict')

您可以进入调试模式,通过使用
pyinstaller--onefile
,所有打印/错误输出都将显示在命令行上。请注意,您必须使用命令行打开程序,双击该程序将无法工作。我知道。脚本在pyinstaller--onefile上运行非常好。但正如我所添加的--窗口化的脚本不再工作了。