Python | pip设置代理 & 更换镜像

问题缘由

之前pip install ...使用国内镜像源提高下载速度,后来学会科学上网后,就不用国内源,一路风雨无阻,今天再运行时,出现如下报错:

WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘ProxyError(‘Cannot connect to proxy.’, timeout(’_ssl.c:1106: The handshake operation timed out’))’: /simple/requests/

知道是代理方面的问题,但是一直没法解决,又能上google,于是还是乖乖换了国内源,这里做个记录,放丢失~

设置代理(cmd, bash, powershell)

网上很多,这里的port应该自己调整~

默认模式:http代理
set http_proxy=http://127.0.0.1:1080
set https_proxy=http://127.0.0.1:1080

bash模式:sock5代理
export https_proxy=socks5://127.0.0.1:1080
export http_proxy=socks5://127.0.0.1:1080

PowerShell :http代理
$env:http_proxy=http://127.0.0.1:1080
$env:https_proxy=http://127.0.0.1:1080

检测命令:curl www.google.com

但是我失败了,设置完问题还在,怀疑可能是v2rayN的问题???大家可以试着把全局模式关了。

这篇8错: 给 Windows 的终端配置代理

更换镜像

镜像(国内源)

  • 阿里云 http://mirrors.aliyun.com/pypi/simple/
  • 中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
  • 豆瓣 http://pypi.douban.com/simple/
  • 清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
  • 中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/

Windows

P.S. 可以永久更改也可以临时使用,我这里就永久更改了
这里以Windows为例:
进入C:\Users\**你的用户名**,创建pip文件夹,接着创建pip.ini文件:
在这里插入图片描述
用文本编辑器打开,输入如下:

[global]
timeout = 6000
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn

然后网速一步起飞,也不会报错了~

也看到有博客直接一句话解决,不用创建文件,没有尝试,大家可以试试。
cmd输入:
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

Linux

修改 ~/.pip/pip.conf,多半一开始是没有的,没有就新建一个:

cd ~ && mkdir .pip
cd .pip && vim pip.conf

如果有,或者新建完了,就修改内容:
vim ~/.pip/pip.conf

加入:
[global]
index-url=http://pypi.douban.com/simple
extra-index-url=
http://mirrors.aliyun.com/pypi/simple/
https://pypi.tuna.tsinghua.edu.cn/simple/
http://pypi.mirrors.ustc.edu.cn/simple/

[install]
trusted-host=
        pypi.douban.com
        mirrors.aliyun.com
        pypi.tuna.tsinghua.edu.cn
        pypi.mirrors.ustc.edu.cn

然后:wq!退出就行了

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值