pip国内镜像源配置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhoulinshijie/article/details/87974824

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

一、常用pip软件源

1.1  pip官方软件源 

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


1.2  常用国内镜像源 


阿里云 http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣 http://pypi.douban.com/simple
中国科学院 http://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=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
    [freeze]
    timeout = 10

猜你喜欢

转载自blog.csdn.net/zhoulinshijie/article/details/87974824