Win10+python3.6+git運行出現(xiàn)問題的解決
Win10+python3.6+git運行出現(xiàn)問題
問題描述
這個問題有點迷,基本就是因為python無法調(diào)用git, 很可能是環(huán)境變量的問題, 設(shè)置了一下,還是不行
如下了下面的錯誤提示:
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.
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 exceptionExample:
export GIT_PYTHON_REFRESH=quiet
During handling of the above exception, another exception occurred:
解決方案
很簡單。。。
在小黑窗中輸入下面的指令即可:
set GIT_PYTHON_GIT_EXECUTABLE=C:\Program Files\Git\cmd\git.exe
應(yīng)該就是手動設(shè)置環(huán)境變量,可以使得python調(diào)用git。
ImportError: Bad git executable錯誤的解決
錯誤具體形式如下:
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 exceptionExample:
export GIT_PYTHON_REFRESH=quiet
出現(xiàn)這個問題,主要要了解并解決兩個問題。
第一個要解決的問題,自己之前是在github上直接通過下載得到的相關(guān)代碼文件,而不是經(jīng)過git clone命令得到的文件。所以導(dǎo)致git出錯。
正確的方法是在github上得到git鏈接(.git形式)
然后在自己本機的特定目錄下運行(xxx.git是在github上得到的git鏈接):
git clone xxx.git
第二個要解決的問題,要將GIT_PYTHON_GIT_EXECUTABLE設(shè)置為自己本機中g(shù)it.exe所在的路徑,可以在git bash中輸入where git命令得到git.exe的路徑,比如說路徑為C:\git\bin\git.exe。
在得知這個路徑后,在自己本機的特定目錄下運行:
set GIT_PYTHON_GIT_EXECUTABLE=C:\git\bin\git.exe
在處理好這兩個問題后,就沒有出現(xiàn)Bad git executable的bug了,成功解決。
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
pandas數(shù)據(jù)探索之合并數(shù)據(jù)示例詳解
這篇文章主要為大家介紹了pandas數(shù)據(jù)探索之合并數(shù)據(jù)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-10-10python實現(xiàn)從字符串中找出字符1的位置以及個數(shù)的方法
這篇文章主要介紹了python實現(xiàn)從字符串中找出字符1的位置以及個數(shù)的方法,對于Python字符串操作的學(xué)習(xí)有一定的幫助與借鑒作用,需要的朋友可以參考下2014-08-08