Skip to content

Windows - ImportError: Failed to initialize: Bad git executable. #816

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
vesche opened this issue Dec 23, 2018 · 16 comments
Closed

Windows - ImportError: Failed to initialize: Bad git executable. #816

vesche opened this issue Dec 23, 2018 · 16 comments

Comments

@vesche
Copy link

vesche commented Dec 23, 2018

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
@Byron
Copy link
Member

Byron commented Dec 24, 2018

Thanks for the detailed report!

To me it appears that maybe it found the executable, but failed to obtain version information from it. It might be possible to learn more by boosting the log-level via GIT_PYTHON_TRACE.

Can you post the results here, if there are any?

@vesche
Copy link
Author

vesche commented Dec 26, 2018

@Byron Thanks for the response! I was able to figure out the problem with your advice. I'm not sure if this is considered a bug- the issue was that I had my git.exe path surrounded by quotes:

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:\>:: However this is awkward because...
C:\>%GIT_PYTHON_GIT_EXECUTABLE% --version
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

I instinctively put quotes around the path to git.exe because it had a space in the path. Likely a trivial fix if considered a bug, something like foo.replace('"', '') around here.

@Byron
Copy link
Member

Byron commented Jan 1, 2019

Thanks a lot for this information! Now it appears clear the issue is with the usage of the respective shell. There must be a way to prevent word splitting when setting variables, other than surrounding it with quotes which would work in bash, for instance.
Something like this should work as expected.

set "VAR_NAME=<String With Spaces>"

@sauravk0302
Copy link

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

@sauravk0302
Copy link

how to solve this problem?

@Byron
Copy link
Member

Byron commented Aug 6, 2020

@sauravk0302 Without any additional information, nothing can be said that isn't already written in this issue.

@AlbertZhangHIT
Copy link

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

@foreverxq
Copy link

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

works for me, thanks。

@fathima-sequoiaat
Copy link

set GIT_PYTHON_REFRESH=quiet

This worked for me

@niladricts
Copy link

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()
set this from windows cmd line

set GIT_PYTHON_REFRESH=quiet

still facing same Import error.

Here's the code:

from pydriller import Repository

for commit in Repository("https://github.com/apache/skywalking.git").traverse_commits():
print(" Hash {} Author {} Message {} ".format(commit.hash, commit.author, commit.msg))

@2601705041
Copy link

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

good

@2601705041
Copy link

2601705041 commented Nov 27, 2022

(plane) D:\PlanarReconstruction-master>python main.py train with dataset.root_dir=D:/PlanarReconstruction-master/data_tools/save/processd/data
WARNING - main - No observers have been added to this run
INFO - main - Running command 'train'
INFO - main - Started
ERROR - main - Failed after 0:00:00!
Traceback (most recent calls WITHOUT Sacred internals):
File "main.py", line 197, in train
network = UNet(cfg.model)
File "D:\PlanarReconstruction-master\models\baseline_same.py", line 48, in init
orig_resnet = resnet.dictcfg.arch
File "D:\PlanarReconstruction-master\models\resnet_scene.py", line 188, in resnet101
model.load_state_dict(load_url(model_urls['resnet101']), strict=True)
File "D:\PlanarReconstruction-master\models\resnet_scene.py", line 199, in load_url
return torch.load(cached_file, map_location=lambda storage, loc: storage)
File "D:\anaconda\envs\plane\lib\site-packages\torch\serialization.py", line 356, in load
f = open(f, 'rb')
FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\peng/.torch\models\resnet101-imagenet.pth'

**i'm very much a beginner,so could someone tell me how to fix it? my enviroment is just like the README said **

@mmhuia
Copy link

mmhuia commented Apr 11, 2023

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

good work

@vijayliebe
Copy link

vijayliebe commented Apr 27, 2023

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"

@BitnaKeum
Copy link

In Linux, export GIT_PYTHON_REFRESH=quiet command works well.

@hamidtech
Copy link

@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 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests