git、pip、easy_install代理设置大全

码农天地 -
git、pip、easy_install代理设置大全

在公司内网环境中,访问公网往往需要经过公司的代理,对于浏览器、IDE等开发工具,都提供了设置代理的配置,对于git、pip、easy_install等CLI工具,则需要通过命令或配置文件进行代理设置,在此做个笔记,避免每次用到了都去Google。

公司内网的代理,访问时往往需要用户名密码,在URL中带用户名密码的格式如下:

http://user:password@proxy_host:port
git代理配置

设置代理

git config --global http.proxy http://user:password@proxy_host:port
git config --global https.proxy http://user:password@proxy_host:port

给指定域名设置代理
如给github.com设置代理

git config --global http.https://github.com.proxy http://user:password@proxy_host:port

取消代理

git config --global --unset http.proxy
git config --global --unset https.proxy
git config --global --unset http.https://github.com.proxy
git代理常见错误处理错误:SSL certificate problem: unable to get local issuer certificate

原因:git默认开启了SSL验证,关闭即可。
解决办法:关闭SSL验证,配合如下。

git config --global http.sslVerify false
git config --global https.sslVerify false
错误:Received HTTP code 407 from proxy after CONNECT

原理:代理认证错误
解决办法:代理配置正确的用户名密码

git config --global http.proxy http://user:password@proxy_host:port
git config --global https.proxy http://user:password@proxy_host:port
pip设置代理直接在命令行中增加--proxy参数来指定代理
pip install numpy --proxy http://user:password@proxy_host:port
通过pip config set命令设置代理
pip config set global.proxy http://user:password@proxy_host:port

这里要注意下,pip官方帮助文档说的设置方法为 pip config [<file-option>] set name value ,这里的name直接写proxy会报ValueError: not enough values to unpack (expected 2, got 1)错误,name要写为<profile>.<key>格式,如这里的global.proxy
此操作和直接改配置文件效果相同,但在不确定配置文件位置的时候,可以使用此操作。

直接修改pip.ini文件进行配置
[global]
proxy=http://user:password@proxy_host:port 
easy_install代理设置

Windows中

set http_proxy=http://user:password@proxy_host:port
set https_proxy=http://user:password@proxy_host:port

Linux中

export http_proxy=http://user:password@proxy_host:port
export https_proxy=http://user:password@proxy_host:port
特别申明:本文内容来源网络,版权归原作者所有,如有侵权请立即与我们联系(cy198701067573@163.com),我们将及时处理。

Tags 标签

加个好友,技术交流

1628738909466805.jpg