遇到的問題:
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
就不會報錯了。