Pycharm运行yolov5报错Error: Failed to initialize: Bad git executable.错误的解决方案

Pycharm运行yolov5报错Error: Failed to initialize: Bad git executable.错误的解决方案

码农世界 2024-05-28 前端 77 次浏览 0个评论

一、报错代码

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

 二、解决办法

1、第一种是直接在train.py文件夹的import os后面加

os.environ["GIT_PYTHON_REFRESH"] = "quiet"

2、第二种是更改git链接

之前是在github上直接通过下载得到的相关代码文件,而不是经过git clone命令得到的文件。所以导致git出错。正确的方法是在github上得到git链接(.git形式)然后在自己本机的特定目录下运行

git clone xxx.git

将GIT_PYTHON_GIT_EXECUTABLE设置为自己本机中git.exe所在的路径,如路径为C:\program\git\bin\git.exe。在得知这个路径后,在自己本机的特定目录下运行:

set GIT_PYTHON_GIT_EXECUTABLE=C:\git\bin\git.exe

转载请注明来自码农世界,本文标题:《Pycharm运行yolov5报错Error: Failed to initialize: Bad git executable.错误的解决方案》

百度分享代码,如果开启HTTPS请参考李洋个人博客
每一天,每一秒,你所做的决定都会改变你的人生!

发表评论

快捷回复:

评论列表 (暂无评论,77人围观)参与讨论

还没有评论,来说两句吧...

Top