编辑:请注意,我已经看到了与此问题有关的其他主题,并且已经尝试了其中的大多数建议
我使用pyinstaller运行.exe文件,现在我正尝试在没有控制台的情况下运行它(使用-w命令)。 我的关键库之一patool使用子进程,该子进程出现以下错误:
Traceback (most recent call last):
File "apscheduler\executors\base.py", line 125, in run_job
File "script.py", line 478, in Archiver
File "patoolib\__init__.py", line 521, in _create_archive
File "patoolib\__init__.py", line 421, in run_archive_cmdlist
File "patoolib\util.py", line 227, in run_checked
File "patoolib\util.py", line 219, in run
File "subprocess.py", line 339, in call
File "subprocess.py", line 753, in __init__
File "subprocess.py", line 1090, in _get_handles
OSError: [WinError 6] The handle is invalid
这是patool util.py代码的一部分,其中包含subprocesses.call(),该错误会给出错误:
def run (cmd, verbosity=0, **kwargs):
"""Run command without error checking.
@return: command return code"""
# Note that shell_quote_nt() result is not suitable for copy-paste
# (especially on Unix systems), but it looks nicer than shell_quote().
if verbosity >= 0:
log_info("running %s" % " ".join(map(shell_quote_nt, cmd)))
if kwargs:
if verbosity >= 0:
log_info(" with %s" % ", ".join("%s=%s" % (k, shell_quote(str(v)))\
for k, v in kwargs.items()))
if kwargs.get("shell"):
# for shell calls the command must be a string
cmd = " ".join(cmd)
if verbosity < 1:
# hide command output on stdout
with open(os.devnull, 'wb') as devnull:
kwargs['stdout'] = devnull
res = subprocess.call(cmd, **kwargs) <------------- ERROR
else:
res = subprocess.call(cmd, **kwargs)
return res
这是一个常见错误,因此我尝试阅读有关子流程模块的信息,并在线上找出每一个可能的建议,包括:
这些都不起作用,处理程序仍然无效。该程序可以在控制台处于活动状态时正常运行。 我正在使用Python 3.7,Anaconda3、64位Windows 10操作系统。
稍后在util.py中有一个subprocess.popen(),我怀疑会导致同样的问题。 我试图通过使控制台处于活动状态然后隐藏它来运行.exe,但是随后遇到其他问题(它在系统启动时无法启动)。我想控制台是很重要的,但是我希望摆脱它以获得更好的用户体验。