Alesi Rowland
Alesi Rowland

Reputation: 441

gitpython can't find git commands despite git being installed

I've install git python, details:

Python 3.8.1
git version 2.21.1 (Apple Git-122.3)
GitPython==3.1.0
gitdb==4.0.2
OS is Catalina
virtual environment via pyenv, pyenv-virtualenv, pyenv-virtualenvwrapper
git is located in /usr/bin/git

running this code:

from git import cmd
import sys

sys.path.append('/usr/bin/')
g = cmd.Git()
g.execute('git') # prints the git help page.
g.execute('git log') # Throws an error. 

g_ = cmd.Git('..')
g_.execute('git'). # prints the git help page.
g_.execute('git log'). # Throws an error. 

Error is:

GitCommandNotFound: Cmd('git') not found due to: FileNotFoundError('[Errno 2] No such file or directory: 'git log'')
cmdline: git log

This is actually an error from a third party library. I've replicated the error from that code with simpler code. original code calls git remote show origin which also has a similar error.

Upvotes: 0

Views: 804

Answers (1)

Omer Tuchfeld
Omer Tuchfeld

Reputation: 3022

execute receives a list of command line arguments, not a single string:

g.execute(['git', 'log']) #  Correct!
g.execute('git log') #  Wrong!
g.execute('git') #  Correct because only a single argument

Upvotes: 1

Related Questions