Win10+python3.6+git运行出现问题的解决
Win10+python3.6+git运行出现问题
问题描述
这个问题有点迷,基本就是因为python无法调用git, 很可能是环境变量的问题, 设置了一下,还是不行
如下了下面的错误提示:
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
应该就是手动设置环境变量,可以使得python调用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
出现这个问题,主要要了解并解决两个问题。
第一个要解决的问题,自己之前是在github上直接通过下载得到的相关代码文件,而不是经过git clone命令得到的文件。所以导致git出错。
正确的方法是在github上得到git链接(.git形式)
然后在自己本机的特定目录下运行(xxx.git是在github上得到的git链接):
git clone xxx.git
第二个要解决的问题,要将GIT_PYTHON_GIT_EXECUTABLE设置为自己本机中git.exe所在的路径,可以在git bash中输入where git命令得到git.exe的路径,比如说路径为C:\git\bin\git.exe。
在得知这个路径后,在自己本机的特定目录下运行:
set GIT_PYTHON_GIT_EXECUTABLE=C:\git\bin\git.exe
在处理好这两个问题后,就没有出现Bad git executable的bug了,成功解决。
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
详谈Python3 操作系统与路径 模块(os / os.path / pathlib)
下面小编就为大家分享一篇详谈Python3 操作系统与路径 模块(os / os.path / pathlib),具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2018-04-04通过Python的filestools库给图片添加全图水印的示例详解
这篇文章主要介绍了通过Python的filestools库给图片添加全图水印,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2023-04-04浅谈tensorflow1.0 池化层(pooling)和全连接层(dense)
本篇文章主要介绍了浅谈tensorflow1.0 池化层(pooling)和全连接层(dense),小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧2018-04-04
最新评论