GitPython: Windows - ImportError: Failed to initialize: Bad git executable.

OS - Win 2012 R2 Python - 2.7.13 git - version 2.20.1.windows.1 GitPython - 2.1.11

GitPython not finding my git.exe binary? C:\Program Files (x86)\Git\cmd is in my PATH. I then explicitly set GIT_PYTHON_GIT_EXECUTABLE as #26 recommends.

C:\Users\Administrator\Desktop>python --version
Python 2.7.13

C:\Users\Administrator\Desktop>pip freeze | findstr /i git
←[33mYou are using pip version 9.0.1, however version 18.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' comm
and.←[0m
gitdb2==2.0.5
GitPython==2.1.11

C:\Users\Administrator\Desktop>echo %GIT_PYTHON_GIT_EXECUTABLE%
"C:\Program Files (x86)\Git\cmd\git.exe"

C:\Users\Administrator\Desktop>%GIT_PYTHON_GIT_EXECUTABLE% --version
git version 2.20.1.windows.1

C:\Users\Administrator\Desktop>python -c "import git"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Python27\lib\site-packages\git\__init__.py", line 85, in <module>
    raise ImportError('Failed to initialize: {0}'.format(exc))
ImportError: 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()

All git commands will error until this is rectified.

This initial warning can be silenced or aggravated in the future by setting the
$GIT_PYTHON_REFRESH environment variable. Use one of the following values:
    - quiet|q|silence|s|none|n|0: for no warning or exception
    - warn|w|warning|1: for a printed warning
    - error|e|raise|r|2: for a raised exception

Example:
    export GIT_PYTHON_REFRESH=quiet

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (3 by maintainers)

Most upvoted comments

@sauravk0302 Hi just type set GIT_PYTHON_REFRESH=quiet in your Windows command line to solve this problem.

@sauravk0302 Hi just type set GIT_PYTHON_REFRESH=quiet in your Windows command line to solve this problem.

That’s work for me too πŸ˜ƒ I use it in my env and I pass this error πŸ‘

In Linux, export GIT_PYTHON_REFRESH=quiet command works well.

Along with GIT_PYTHON_GIT_EXECUTABLE, I needed to export also GIT_SSH_COMMAND. These worked for me. :-

export PATH=$PATH:/usr/bin/git
export GIT_PYTHON_GIT_EXECUTABLE=/usr/bin/git
export GIT_SSH_COMMAND="/usr/bin/ssh -i ~/.ssh/id_rsa"