栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

更换python的pip下载国内源

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

更换python的pip下载国内源

目录

0.前言

1.临时使用国内源

2.永久修改

2.1方法一:修改配置文件。

2.1.1 Mac/Linux

2.1.1 Windows

2.2方法二:使用命令行(所有系统都适用)

3.写在最后



0.前言

最近需要反复给计算机安装python和anaconda环境,在默认情况下 pip 使用的是国外的软件包源,在下载的时候的速度很慢,花费的时间比较长。故而需要给anaconda和pip安装国内镜像源。这里就简单的记录下我了解的方法,方便我,也方便大家使用。

常见的国内源如下

清华:https://pypi.tuna.tsinghua.edu.cn/simple
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
华中理工大学:http://pypi.hustunique.com/
阿里云:http://mirrors.aliyun.com/pypi/simple/
豆瓣:http://pypi.douban.com/simple/
百度:https://mirror.baidu.com/pypi/simple

1.临时使用国内源

平时我们在安装的时候都是使用的pip install xxx来安装python包,这里如果是零时使用国内原只需要在后面补上-i xxx,这里xxx为国内源的网址。以使用清华源下载opencv-python为例,如下:

pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple

2.永久修改

2.1方法一:修改配置文件。

2.1.1 Mac/Linux

在Mac/Linux系统下:配置文件位置在 ~/.pip/pip.conf

如果是新安装的就没有这个文件,需要自己创建.pip目录:

mkdir ~/.pip

完成后,打开pip.conf修改为(以清华源为例):

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

最后使用查看是否修改了:

pip config list   

如果出现下面文字就说明修改成功了:

global.index-url='https://pypi.tuna.tsinghua.edu.cn/simple'
install.trusted-host='https://pypi.tuna.tsinghua.edu.cn'

2.1.1 Windows

        win环境pip的配置文件在C:UsersxxxAppDataRoamingpippip.ini里面,可以打开此文件(没有就自己创建一个)直接修改,同样以清华源为例:

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

同样可用pip config list 查看。出现下面的文字就表示成功了

global.index-url='https://pypi.tuna.tsinghua.edu.cn/simple'
install.trusted-host='https://pypi.tuna.tsinghua.edu.cn'

2.2方法二:使用命令行(所有系统都适用)

输入下面的命令可直接永久设置为清华源。

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

同样可以使用pip config list查看是否设置成功:出现下面的文字就表示成功了

global.index-url='https://pypi.tuna.tsinghua.edu.cn/simple'
install.trusted-host='https://pypi.tuna.tsinghua.edu.cn'

3.写在最后

上述的例子都是以清华源为例,除此之外,还可以更换为其他所有的国内镜像(替换清华源网址即可)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/923914.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号