如何安装 gitpython,初始化失败:错误的 git 可执行文件

How to install gitpython with, Failed to initialize: Bad git executable

我正在尝试在 Windows 上安装 git-python。我尝试使用 git 命令安装它:

pip install gitpython

它安装得很好并且安装在我的本地应用程序数据中。唯一的问题是当我 运行 它时,它给了我这个错误:

初始化失败:错误的 git 可执行文件。 git 可执行文件必须以下列方式之一指定:

另外我运行 pip install gitpython:

要求已满足:gitpython in c:\users\morga\appdata\local\programs\python\python38-32\lib\site-packages (3.1.3) 要求已经满足:gitdb<5,>=4.0.1 in c:\users\morga\appdata\local\programs\python\python38-32\lib\site-packages (from gitpython) (4.0.5) 已满足要求:c:\users\morga\appdata\local\programs\python\python38-32\lib\site-packages 中的 smmap<4,>=3.0.1(来自 gitdb<5,>=4.0.1->gitpython) (3.0.4)

我没有 git 的文件夹。我只在我的 appdata local

中发现任何远程到 git 的东西

issue 816 一样,检查您的 GIT_PYTHON_GIT_EXECUTABLE 环境变量:

C:\>:: This does NOT work
C:\>set GIT_PYTHON_GIT_EXECUTABLE="C:\Program Files\Git\cmd\git.exe"
C:\>%GIT_PYTHON_GIT_EXECUTABLE% --version
git version 2.20.1.windows.1

C:\>:: This does work
C:\>set GIT_PYTHON_GIT_EXECUTABLE=C:\Program Files\Git\cmd\git.exe

C:\Program Files\Git\ 替换为您自己的 Git 安装文件夹(使用,如 by Jeromy Adofowhere git)。
如果你没有安装 Git,你可以安装最新的 Git For Windows.