ImportError: Bad git executable.
问题
再Gitee上下载的代码,使用pytorch虚拟环境在本地执行的时候报错:ImportError: Bad git executable.
Traceback (most recent call last):
File "C:\Users\chendujiang\AppData\Roaming\Python\Python39\site-packages\git\__init__.py", line 89, in <module>
refresh()
File "C:\Users\chendujiang\AppData\Roaming\Python\Python39\site-packages\git\__init__.py", line 76, in refresh
if not Git.refresh(path=path):
File "C:\Users\chendujiang\AppData\Roaming\Python\Python39\site-packages\git\cmd.py", line 392, in refresh
raise ImportError(err)
ImportError: 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.
解决办法
找到虚拟环境的位置:anaconda\envs\classification\Lib\site-packages\git 文件夹下的cmd.py
**注意:::**根据报错信息到指定的位置修改cmd.py,不一定是上述的位置: File “C:\Users\chendujiang\AppData\Roaming\Python\Python39\site-packages\git\cmd.py”,
line 392, in refresh,这就是要去这个位置:C:\Users\chendujiang\AppData\Roaming\Python\Python39\site-packages\git\
打开文件,并加一段代码:
os.environ['GIT_PYTHON_REFRESH'] = 'quiet'