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

时间:2019-04-08 21:48:50

标签: python python-3.x subprocess

我正在尝试使用子流程来调用我当前的脚本,如下所示:

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

我可能做错了什么?

1 个答案:

答案 0 :(得分:1)

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

sb.call(['python3', current_path], shell=True)
相关问题