2

我试过了

g = git.Repo(r'C:\Users\Administrator\Desktop\testRepo')
print g.untracked_files

但得到:

git.exc.GitCommandNotFound:[错误 2]

它是一个错误吗?

4

1 回答 1

6

当我做同样的事情时,我没有这个错误。

git您的 ${PATH} 变量中有可执行文件吗?如果您使用的是 bash,则可以运行 export PATH=$PATH:/path/to/your/git/executable

来自:exc.py_gitpython

class GitCommandNotFound(Exception): """Thrown if we cannot find thegit executable in the PATH or at the path given by the GIT_PYTHON_GIT_EXECUTABLE environment variable""" pass one 可以假设设置该环境变量也可能有所帮助。

您还可以直接从 python 以独立于平台的方式设置 env 变量,如此处所述,而不是修改您的启动脚本(又名 ~/.bash_profile 或类似的):

Python:修改 PATH 环境变量的平台无关方式

于 2015-09-29T13:35:34.250 回答