[转载] git 和 pip 代理设置

转载自这位老哥:
https://blog.csdn.net/liu940129953/article/details/107358559

//首先,设置默认代理,也可以理解为清除代理
git config --global --unset http.proxy
git config --global --unset https.proxy
 
//设置代理
git config --global http.proxy "socks5://127.0.0.1:7890"
git config --global https.proxy "socks5://127.0.0.1:7890"

// 有公司的填写你们公司的代理
git config --global http.proxy http://proxy.xxx.com:8080 
git config --global https.proxy https://proxy.xxx.com:8080

// v2rayN 的端口默认为 10808
git config --global http.proxy "socks5://x.x.139.7:10808"
git config --global https.proxy "socks5://x.x.139.7:10808"

端口要自己改

在这里插入图片描述

参考本文的单次设置:
https://zhuanlan.zhihu.com/p/371953325

pip install -r requirements.txt --proxy="socks5://127.0.0.1:7890"
ERROR: Could not install packages due to an OSError: Missing dependencies for SOCKS support.

WARNING: There was an error checking the latest version of pip.

参考这里:
1. https://stackoverflow.com/questions/38794015/pythons-requests-missing-dependencies-for-socks-support-when-using-socks5-fro
2. https://blog.csdn.net/whatday/article/details/109287343

$ pip install pysocks

即可

如果直接安装出现:

> pip install -r requirements.txt --proxy="socks5://127.0.0.1:7890"
Looking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1131)'))': /simple/cython/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1131)'))': /simple/cython/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1131)'))': /simple/cython/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1131)'))': /simple/cython/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1131)'))': /simple/cython/
Could not fetch URL https://pypi.org/simple/cython/: There was a problem confirming the ssl certificate: SOCKSHTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/cython/ (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1131)'))) - skipping

ERROR: Could not find a version that satisfies the requirement Cython==0.29.17 (from versions: none)
ERROR: No matching distribution found for Cython==0.29.17
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: SOCKSHTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1131)'))) - skipping
WARNING: There was an error checking the latest version of pip.

则换个源即可:

pip install -r requirements.txt --proxy="socks5://127.0.0.1:7890" -i https://mirror.baidu.com/pypi/simple

linux环境变量设置代理:

$ export http_proxy=http://proxy.xxxx.com:8080
$ export https_proxy=http://proxy.xxxx.com:8080

当然,之后我们可能想不用这个代理,该怎么搞呢?

# 先看一下本机有哪些代理:
env | grep -i proxy
$ export http_proxy=http://proxy.xxxx.com:8080
$ export https_proxy=http://proxy.xxxx.com:8080

取消http的代理:

unset http_proxy

取消https的代理:

unset https_proxy

摘自:
https://blog.csdn.net/weixin_42237113/article/details/108667768

pip更改默认镜像源

给 pip 换源

pip的配置文件在linux系统中为:

~/.pip/pip.conf

若上述配置文件不存在,则手动创建。
也可通过下面的命令查看配置文件位置:

pip -v config list

找到pip的配置文件后,以阿里云镜像为例,修改文件内容为:

[global]
index-url=http://mirrors.aliyun.com/pypi/simple/
trusted-host=mirrors.aliyun.com

以下是windows系统的

进入AppData目录
文件管理地址栏输入%APPDATA%,即可快速进入。
如果你的用户是Administrator可以使用下列地址手动进入:
C:\Users\Administrator\AppData\Roaming

新建pip目录
新建配置文件
在刚刚新建的pip目录中,新建pip.ini文件,文件内容如下:

[global]
index-url=http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com

参考自:
https://www.jianshu.com/p/d0bca98f4014

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值