简体   繁体   中英

Unable to run Git command from Python script

When using subprocess.call("git sparse-checkout") to execute a git command it returns an error saying that the git command doesn't exist:

git: 'sparse-checkout' is not a git command. See 'git --help'.

When running the same command in the terminal, however, I am able to use sparse-checkout with no problems.

I have also tried to use the following:

subprocess.call(['git', 'sparse-checkout'])
subprocess.call("git sparse-checkout", shell=True)
os.system("git sparse-checkout")

All return the same result.

I am using git 2.26.2 and Python 3.2 on RHEL 6.6

The error you are getting about 'sparce-checkout' is not a git command points to the version of git the script is initializing is not >= git 2.26.

It looks like this is a relatively new command with git. Two things I would do:

  1. Verify the version of git the script is initializing and what you see in the terminal
    subprocess.call(["which", "git"]) subprocess.call(["git", "--version"])
  2. If there are multiple versions of git use the full path to the binary

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM