pythonpython-3.xgitgitpython

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


I am trying to install git-python on Windows. I tried to install it using the git command:

pip install gitpython

It installed just fine and it install in my local app data. The only problem was is when I ran it, it gave me this error:

Failed to initialize: Bad git executable.
The git executable must be specified in one of the following ways:

- be included in your $PATH
- be set via $GIT_PYTHON_GIT_EXECUTABLE
- explicitly set via git.refresh()

In addition I ran pip install gitpython:

Requirement already satisfied: gitpython in c:\users\morga\appdata\local\programs\python\python38-32\lib\site-packages (3.1.3)
Requirement already satisfied: gitdb<5,>=4.0.1 in c:\users\morga\appdata\local\programs\python\python38-32\lib\site-packages (from gitpython) (4.0.5)
Requirement already satisfied: smmap<4,>=3.0.1 in c:\users\morga\appdata\local\programs\python\python38-32\lib\site-packages (from gitdb<5,>=4.0.1->gitpython) (3.0.4)

I do not have it the folder of git. I only found anything remotely to git was in my appdata local


Solution

  • As in issue 816, check your GIT_PYTHON_GIT_EXECUTABLE environment variable:

    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
    

    Replace C:\Program Files\Git\ by your own Git installation folder (using, as noted by Jeromy Adofo, where git).
    If you don't have Git installed, you can installed the latest Git For Windows.