Python: ImportError: Bad git executable

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'

在这里插入图片描述

问题解决!!!!

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值