开发手册 欢迎您!
软件开发者资料库

Python PIP 配置国内源的方法

Python中,使用PIP安装软件包时,有时间下载比较慢,这可能是由于软件包源服务器https://pypi.org/ 在国外访问速度比较慢,可以将源地址改成国内地址解决这个问题,本文主要介绍Python PIP 配置成国内源的方法。

1、PIP简介

参考文档Python PIP简介及安装

2、PIP国内源

1)清化大学

PIP源地址https://pypi.tuna.tsinghua.edu.cn/simple

2)阿里云

PIP源地址http://mirrors.aliyun.com/pypi/simple/

3)豆瓣

PIP源地址http://pypi.douban.com/simple/

4)中国科学技术大学

PIP源地址http://pypi.mirrors.ustc.edu.cn/simple/

5)华中科技大学

PIP源地址http://pypi.hustunique.com/

3、临时配置国内源方法

下面以使用pip安装numpy为例安装:

pip install numpy -i http://mirrors.aliyun.com/pypi/simple/ 

或者

pip3 install numpy -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

注意--trusted-host表示信任源地址

4、永久配置使用国内源方法

永久配置使用国内源需要在pip.conf配置文件添加地址,具体pip.conf文件配置内容如下:

[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple[install]trusted-host = https://pypi.tuna.tsinghua.edu.cn  # trusted-host 此参数是为了解决地址不受信任问题

1) Linux/Mac添加修改pip.conf配置文件

mkdir ~/.pip
touch pip.conf
vim ~/.pip/pip.conf

粘贴进去上述配置文件内容即可。

2)Windows添加修改pip.conf配置文件

打开 C:\Users\当前用户名 目录下,新建pip文件夹,进到文件夹中创建pip.ini文件,粘贴进去上述配置文件内容即可。