subprocess.check_call: 命令'['git', 'clone']' 返回非零退出状态 127

subprocess.check_call: Command '['git', 'clone']' returned non-zero exit status 127

我正在开发一个微服务,为此为用户编写了以下脚本,该用户希望 ssh 进入远程环境并 git clone 一个存储库。我已经为环境指定了 GIT_SSHGIT_PYTHON_GIT_EXECUTABLE,然后是 运行 git clone.

def clone_if_local_repo_absent(local_repo_path, remote_repo_url):
    GIT_SSH = '...'
    GIT_PYTHON_GIT_EXECUTABLE = '/usr/bin/git'
    my_env = os.environ.copy()
    my_env["GIT_SSH"] = GIT_SSH
    my_env["GIT_PYTHON_GIT_EXECUTABLE"] = GIT_PYTHON_GIT_EXECUTABLE
    # Clones to directory specified
    exe_command = shlex.split('git clone {remote_repo_url} {repo_name}'.format(remote_repo_url=remote_repo_url, repo_name=local_repo_path))
    subprocess.check_call(exe_command, env=my_env, shell=True)

在 运行 脚本上,我收到错误:Command '['git', 'clone', remote_repo_url, 'LOCAL']' returned non-zero exit status 127. 我该如何解决这个错误?

Git ProBook所述:

GIT_SSH, if specified, is a program that is invoked instead of ssh when Git tries to connect to an SSH host.
It is invoked like $GIT_SSH [username@]host [-p <port>] <command>.

Note that this isn’t the easiest way to customize how ssh is invoked; it won’t support extra command-line parameters, so you’d have to write a wrapper script and set GIT_SSH to point to it.
It’s probably easier just to use the ~/.ssh/config file for that.

所以这根本不会在远程端执行。它被执行以连接到远程服务器。

如果 Git 没有安装在远程环境中,任何从 ssh 会话执行的 git clone 都不会起作用。