子进程找不到我的文件(找不到文件错误)

问题描述 投票:1回答:1

我试图使用子进程来调用我当前的脚本,如下所示:

import subprocess as sb
current_path = os.path.realpath(__file__)
sb.call(['python3', current_path])

但是,我最终会:

FileNotFoundError: [WinError 2] The system cannot find the file specified

我能做错什么?

python python-3.x subprocess
1个回答
1
投票

python3.exe不存在于PATH环境变量的任何路径中。使用绝对路径来指定python3.exe,或使用shell=True参数:

sb.call(['python3', current_path], shell=True)
© www.soinside.com 2019 - 2024. All rights reserved.