Liunx下pip3换源(最详细)

  • Post author:
  • Post category:其他


在使用python时我们经常会安装各种包,我们一般安装的方式都是pip3 install xx模块,但是pip3默认源https://pypi.org/安装的过程非常慢,可能都是几k几k的,有时安装这安装着,直接error了,还有一种情况是直接飘黄,警告,然后就一直警告,如下图所示

因此我们需要将源换成国内的源

目前国内常用的源:

阿里云 https://mirrors.aliyun.com/pypi/simple/

豆瓣 https://pypi.douban.com/simple/

清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/

中国科学技术大学 https://pypi.mirrors.ustc.edu.cn/simple/

华中科技大学https://pypi.hustunique.com/

换源命令:

pip3 config set global.index-url   源地址
 
例如换成阿里云源则需要执行:
pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple/

但是在换源时使用pip3 config set 国内源,提示如下错误:


pip3 ERROR: unknown command "config"

原因是pip3版本过低,不支持config方法

#升级pip到最新版本

sudo -H pip3 install -U pip

#重新运行pip3 config

sudo pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple/

这样就解决了问题了


特别提醒


换源时使用https协议的源地址  否则在安装模块是会失败并有warning因为http不受信任就是不安全 要不然安装的时候再后面加上



-trusted-host mirrors.aliyun.com 但是这样太麻烦所以直接换源的时候用https的源址



版权声明:本文为qq_42402086原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。