【发布时间】:2015-12-26 22:18:43
【问题描述】:
我试过了
g = git.Repo(r'C:\Users\Administrator\Desktop\testRepo')
print g.untracked_files
但是得到了:
git.exc.GitCommandNotFound: [错误 2]
这是一个错误吗?
【问题讨论】:
-
你使用的是哪个版本的 git 和 gitpython?
我试过了
g = git.Repo(r'C:\Users\Administrator\Desktop\testRepo')
print g.untracked_files
但是得到了:
git.exc.GitCommandNotFound: [错误 2]
这是一个错误吗?
【问题讨论】:
当我做同样的事情时,我没有这个错误。
您的 ${PATH} 变量中是否有 git 可执行文件?
如果您使用的是 bash,则可以运行
export PATH=$PATH:/path/to/your/git/executable
来自exc.py 中的gitpython:
class GitCommandNotFound(Exception):
"""Thrown if we cannot find thegitexecutable in the PATH or at the path given by
the GIT_PYTHON_GIT_EXECUTABLE environment variable"""
pass
可以假设设置该环境变量也可能有所帮助。
您还可以直接从 python 以独立于平台的方式设置环境变量,如这里详细描述的那样,而不是修改您的启动脚本(又名 ~/.bash_profile 或类似的):
Python: Platform independent way to modify PATH environment variable
【讨论】: