我试图使用子进程来调用我当前的脚本,如下所示:
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
我能做错什么?
python3.exe
不存在于PATH
环境变量的任何路径中。使用绝对路径来指定python3.exe
,或使用shell=True
参数:
sb.call(['python3', current_path], shell=True)