Python 带有Subprocess.popen的Pyinstaller作为exe失败
当使用pyInstaller创建exe时,我正在努力实现子流程 我有一个程序,它有一个gui(tkinter),其中多个按钮都有它们的subprocess.popen()。有一个通过ssh发送到网络设备的命令需要一些时间才能完成 在pyCharm中,此操作平稳。 使用pyInstaller创建exe时,出现以下错误:Python 带有Subprocess.popen的Pyinstaller作为exe失败,python,tkinter,subprocess,pyinstaller,Python,Tkinter,Subprocess,Pyinstaller,当使用pyInstaller创建exe时,我正在努力实现子流程 我有一个程序,它有一个gui(tkinter),其中多个按钮都有它们的subprocess.popen()。有一个通过ssh发送到网络设备的命令需要一些时间才能完成 在pyCharm中,此操作平稳。 使用pyInstaller创建exe时,出现以下错误: Exception in Tkinter callback Traceback (most recent call last): File "tkinter\__init__
Exception in Tkinter callback
Traceback (most recent call last):
File "tkinter\__init__.py", line 1699, in __call__
File "gui.py" in line 197 in wrapper
File "subprocess.py", line 707, in __init__
File "subprocess.py", line 990, in _execute_child
FileNotFoundError: [WinError 2] The system cannot find the file specified
key not found: process1
gui.py行197的相应代码为:
proc = subprocess.Popen(['python', r'commands/pec_cmd.py',
str(cmd), pec_ip, '1', '0', '0', '0', '0'],
startupinfo=subprocess.STARTUPINFO(), env=os.environ,
stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
稍后,我将该进程存储在dict中,该dict在前面使用subaccess={}初始化:
subprocesses['process' + str(i)] = proc
知道我为什么会遇到这个FileNotFoundError吗?
从PyCharm运行时,它可以工作,但一旦创建了exe(--onedir和--onefile trusted),它就会失败您需要确定找不到哪个文件
python.exe
或commands/pec_cmd.py
您可以尝试在当前shell中运行子流程:subprocess.Popen(…shell=True)
或使用子流程的完整路径
subprocess.Popen(['c:/python/python.exe', r'c:/whateverPath/commands/pec_cmd.py'])
但您仍然依赖于预先安装的Python解释器:假设您想在另一台未安装Python的计算机上运行应用程序/exe,子进程将失败,或者您将始终需要安装Python。谢谢@Maurice Meyer。我并不害怕这样一个事实,那就是仍然需要安装python。因此我将其更改为调用exe: 现在,当直接用exe而不是用脚本pec_cmd.py调用
subprocess.popen(“python”,commands/pec_cmd.py“,…)
时,它可以工作,而不是调用subprocess.popen(“pec_cmd.exe”),…)