隐藏控制台并执行 python 脚本

2024-05-03

我正在尝试使用 pyinstaller 在 Windows 10 上使用 pyqt5 模块编译在 python 3 中构建的 python 脚本,该脚本在运行时隐藏窗口。

为了编译我的脚本,我执行了以下命令:

pyinstaller --onefile --icon=app.ico --clean --noconsole app.py

但是我得到的可执行文件不起作用,所以我再次通过以下命令编译了我的脚本:

 pyinstaller --onefile -w --icon=app.ico  app.py

如果出现以下情况,输出可执行文件仍然无法工作--控制台/-w/--窗口使用参数。

如何让我的可执行文件在没有控制台的情况下运行?

这是我尝试执行的脚本

import threading
import subprocess
import sys
import time

f = open("build\\eco.txt", "x")
f = open("build\\sou.txt", "x")

def run_process(path):
    cmd = 'python %s' % path
    process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
    for line in iter(process.stdout.readline, ''):
        sys.stdout.write(line)


t1 = threading.Thread(target=run_process, args=('py1.py',))
t2 = threading.Thread(target=run_process, args=('py2.py',))
t3 = threading.Thread(target=run_process, args=('py3.py',))
t4 = threading.Thread(target=run_process, args=('py4.py',))
t5 = threading.Thread(target=run_process, args=('py5.py',))


#start
t1.start()
t2.start()
t3.start()
t4.start()
t5.start()

# Waiting
t1.join()
t2.join()
t3.join()
t4.join()
t5.join()

Thanks


pass -w 或 --windowed 或 --noconsole隐藏控制台的标志。

通过安装尝试 GUI pyinstaller自动 py 到 exe。它使您更容易编译脚本。

pip install auto-py-to-exe
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

隐藏控制台并执行 python 脚本 的相关文章

随机推荐