0

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.

Alesi Rowland
  • 379
  • 2
  • 16
  • 2
    `sys.path` is NOT the same as `os.environ['PATH']`. `sys.path` is the parsed environment variable `PYTHONPATH` which refers to where to import Python packages from, not where to find executables. What's your current value of `os.environ['PATH']`? – Omer Tuchfeld Mar 13 '20 at 15:54
  • '/Users/alesi/.virtualenvs/scrape_horses/bin:/Users/alesi/.pyenv/versions/3.8.1/bin:/usr/local/Cellar/pyenv/1.2.16/libexec:/Users/alesi/.pyenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin' at debug on exception. – Alesi Rowland Mar 13 '20 at 15:55

1 Answers1

1

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
Omer Tuchfeld
  • 2,886
  • 1
  • 17
  • 24