pip国内镜像源配置

python从国外源下载安装包,会特别慢,还会经常出现下载失败的情况,所以我们要从国内源下载安装包。

一、常用pip软件源

1.1  pip官方软件源 

官方源 https://pypi.python.org/simple


1.2  常用国内镜像源 


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

1.3 临时指定软件源


通常来讲,如果想要手动指定临时软件源来安装软件的话,可是使用如下格式
    pip install -i xx(其中xx是指定的源ip地址)

例如,使用豆瓣源来安装jieba包
    pip install jieba -i https://pypi.douban.com/simple

1.4  永久指定软件源


如果想要使pip的配置永久生效,就要使用配置文件方式。针对不同的系统,配置文件稍稍有所不同。

1.4.1  针对当前用户

在UNIX系统中默认的配置文件是: **$HOME/.config/pip/pip.conf**。 which respects the XDG_CONFIG_HOME environment variable。
在macOS系统中配置文件是:**$HOME/Library/Application Support/pip/pip.conf**。在$HOME/Library/Application Support/pip/目录不存在的情况下,也可是是**$HOME/.config/pip/pip.conf**。
在Windows系统中默认的配置文件是:**%APPDATA%\pip\pip.ini**。

pip也支持经典的每个用户一个配置文件的方式,具体的位置是:

Unix 和 macOS 配置文件: **$HOME/.pip/pip.conf**
Windows t配置文件: **%HOME%\pip\pip.ini**
当然,也可是使用环境变量PIP_CONFIG_FILE来自定义配置文件位置


1.4.2  针对虚拟环境

Unix 和 macOS 下文件是: $VIRTUAL_ENV/pip.conf
Windows 下的文件是: %VIRTUAL_ENV%\pip.ini


1.4.3  针对整个系统


Unix 配置文件 /etc/pip.conf. 当然也可以是一个任何路径下的 “pip” 子目录,然后通过环境变量XDG_CONFIG_DIRS来指定, 例如/etc/xdg/pip/pip.conf.
macOS 配置文件: /Library/Application Support/pip/pip.conf
Windows XP 配置文件: C:\Documents and Settings\All Users\Application Data\pip\pip.ini
Windows 7 及其更高版本的配置文件是隐藏的, 就可以在C:\ProgramData\pip\pip.ini中写入
Site-wide configuration is not supported on Windows Vista


1.4.4  配置文件的级别


If multiple configuration files are found by pip then they are combined in the following order:

The site-wide file is read
The per-user file is read
The virtualenv-specific file is read

Each file read overrides any values read from previous files, so if the global timeout is specified in both the site-wide file and the per-user file then the latter value will be used.

1.5  pip多镜像源配置文件内容

[global]
    timeout=60
    index-url=https://pypi.douban.com/simple
    extra-index-url=https://mirrors.aliyun.com/pypi/simple/
            https://pypi.tuna.tsinghua.edu.cn/simple/
            https://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
    [freeze]
    timeout = 10

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值