开发者社区 问答 正文

尽管安装了git,但gitpython找不到git命令

我已经安装了git python,详细信息:

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

运行此代码:

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. 

错误是:

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

这实际上是来自第三方库的错误。我已经用更简单的代码复制了该代码中的错误。原始代码调用git remote show origin,它也有类似的错误。

问题来源:stackoverflow

展开
收起
is大龙 2020-03-23 21:01:09 2077 分享 版权
1 条回答
写回答
取消 提交回答
  • execute接收命令行参数列表,而不是单个字符串:

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

    回答来源:stackoverflow

    2020-03-23 21:01:16
    赞同 展开评论