Carter Montgomery
Carter Montgomery

Reputation: 11

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

Upvotes: 1

Views: 373

Answers (1)

RobertoS
RobertoS

Reputation: 61

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

Upvotes: 1

Related Questions