我试过了
g = git.Repo(r'C:\Users\Administrator\Desktop\testRepo')
print g.untracked_files
但得到:
git.exc.GitCommandNotFound:[错误 2]
它是一个错误吗?
当我做同样的事情时,我没有这个错误。
git
您的 ${PATH} 变量中有可执行文件吗?如果您使用的是 bash,则可以运行
export PATH=$PATH:/path/to/your/git/executable
来自:exc.py
_gitpython
class GitCommandNotFound(Exception):
"""Thrown if we cannot find the
git executable in the PATH or at the path given by
the GIT_PYTHON_GIT_EXECUTABLE environment variable"""
pass
one 可以假设设置该环境变量也可能有所帮助。
您还可以直接从 python 以独立于平台的方式设置 env 变量,如此处所述,而不是修改您的启动脚本(又名 ~/.bash_profile 或类似的):