当前位置: 首页 > news >正文

跑yolov5的train.py时,ImportError: Failed to initialize: Bad git executable.

遇到的问题:

Traceback (most recent call last):File "D:\miniconda\envs\yolov5\lib\site-packages\git\__init__.py", line 296, in <module>refresh()File "D:\miniconda\envs\yolov5\lib\site-packages\git\__init__.py", line 287, in refreshif not Git.refresh(path=path):File "D:\miniconda\envs\yolov5\lib\site-packages\git\cmd.py", line 877, in refreshraise ImportError(err)
ImportError: GIT_PYTHON_REFRESH environment variable has been set but it has been set with an invalid value.Use only the following values:- quiet|q|silence|s|silent|none|n|0: for no message or exception- warn|w|warning|log|l|1: for a warning message (logging level CRITICAL, displayed by default)- error|e|exception|raise|r|2: for a raised exceptionThe above exception was the direct cause of the following exception:Traceback (most recent call last):File "train.py", line 66, in <module>GIT_INFO = check_git_info()File "D:\miniconda\envs\yolov5\lib\contextlib.py", line 75, in innerreturn func(*args, **kwds)File "C:\Users\莫伟铎\Desktop\yolov5-7.0\utils\general.py", line 350, in check_git_infoimport gitFile "D:\miniconda\envs\yolov5\lib\site-packages\git\__init__.py", line 298, in <module>raise ImportError("Failed to initialize: {0}".format(_exc)) from _exc
ImportError: Failed to initialize: GIT_PYTHON_REFRESH environment variable has been set but it has been set 
with an invalid value.Use only the following values:- quiet|q|silence|s|silent|none|n|0: for no message or exception- warn|w|warning|log|l|1: for a warning message (logging level CRITICAL, displayed by default)- error|e|exception|raise|r|2: for a raised exception
 File "D:\miniconda\envs\yolov5\lib\site-packages\git\__init__.py", line 296, in <module>refresh()File "D:\miniconda\envs\yolov5\lib\site-packages\git\__init__.py", line 287, in refreshif not Git.refresh(path=path):File "D:\miniconda\envs\yolov5\lib\site-packages\git\cmd.py", line 860, in refreshraise 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(<full-path-to-git-executable>)All git commands will error until this is rectified.This initial message 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|silent|none|n|0: for no message or exception- warn|w|warning|log|l|1: for a warning message (logging level CRITICAL, displayed by default)- error|e|exception|raise|r|2: for a raised exceptionExample:export GIT_PYTHON_REFRESH=quietThe above exception was the direct cause of the following exception:Traceback (most recent call last):File "train.py", line 66, in <module>GIT_INFO = check_git_info()File "D:\miniconda\envs\yolov5\lib\contextlib.py", line 75, in innerreturn func(*args, **kwds)File "C:\Users\莫伟铎\Desktop\yolov5-7.0\utils\general.py", line 350, in check_git_infoimport gitFile "D:\miniconda\envs\yolov5\lib\site-packages\git\__init__.py", line 298, in <module>raise ImportError("Failed to initialize: {0}".format(_exc)) from _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(<full-path-to-git-executable>)All git commands will error until this is rectified.This initial message 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|silent|none|n|0: for no message or exception- warn|w|warning|log|l|1: for a warning message (logging level CRITICAL, displayed by default)- error|e|exception|raise|r|2: for a raised exceptionExample:export GIT_PYTHON_REFRESH=quiet

原因:

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(<full-path-to-git-executable>)

解决办法:

下载并安装 Git:

下面是其官网:https://git-scm.com/download/win

点击画圈圈的Click here download,进行下载git

        安装完git后,重启终端(CMD / PowerShell)再运行:输入git --version出现相应的版本号说明安装成功。

git --version
# 应输出:git version 2.x.x

出现下面情况就是安装成功。

然后输入指令:

python train.py

就不会报错了。

http://www.lryc.cn/news/610724.html

相关文章:

  • 前端实现Excel文件的在线预览效果
  • 【机器学习】算法调参的两种方式:网格搜索(枚举)、随机搜索
  • 【力扣 Hot100】 刷题日记
  • Python分块读取大型Excel文件
  • 豆包新模型与 PromptPilot 实操体验测评,AI 辅助创作的新范式探索
  • LangGraph学习笔记 — LangGraph中State状态模式
  • 自动驾驶控制算法——MPC控制算法
  • qq scheme
  • GaussDB 并行创建索引
  • 使用iptables的nat链表进行端口转发
  • 基于MATLAB实现的频域模态参数识别方法
  • 算法3. 无重复字符的最长子串
  • Django中的转发与重定向详解
  • Boosting 知识点整理:机制、对比与应用场景
  • 统计鱼儿分布情况 Java
  • 复制网页文字到Word、WPS文字?选中后直接拖放
  • C语言线程同步详解(互斥锁、信号量、条件变量和读写锁)
  • Apache OFBiz Scrum 组件命令注入漏洞
  • FLAN-T5:大规模指令微调的统一语言模型框架
  • C++(线程)
  • 恶魔轮盘赌
  • Java Date类介绍
  • 前端保持和服务器时间同步的方法【使用vue3举例】
  • 利用m0改造循迹模块处理笔记00
  • 强光干扰下误报率↓82%!陌讯多模态融合算法在火焰识别的落地优化
  • 服务器数据恢复—坏道致Raid5阵列硬盘离线如何让数据重生?
  • Linux 系统启动原理2
  • 2025年服务器漏洞生存指南:从应急响应到长效免疫的实战框架
  • Pandas query() 方法详解
  • 防水防尘防摔性能很好的智能三防手机,还有22000mAh大电池