在公司内网环境中,拜访公网往往须要通过公司的代理,对于浏览器、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:portgit 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.proxygit config --global --unset https.proxygit config --global --unset http.https://github.com.proxy

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:portset https_proxy=http://user:password@proxy_host:port

Linux中

export http_proxy=http://user:password@proxy_host:portexport https_proxy=http://user:password@proxy_host:port