由于 python 自带的源有时候下载不了且速度慢,可以替换国内源
指令方式
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple
pip config set install.trusted-host mirrors.aliyun.com
手动方式
- 获取pip的配置文件位置
pip -v config list
或
pip3 -v config list
For variant ‘global’, will try loading ‘/etc/xdg/xdg-ubuntu/pip/pip.conf’
For variant ‘global’, will try loading ‘/etc/xdg/pip/pip.conf’
For variant ‘global’, will try loading ‘/etc/pip.conf’
For variant ‘user’, will try loading ‘/home/tan/.pip/pip.conf’
For variant ‘user’, will try loading ‘/home/tan/.config/pip/pip.conf’
For variant ‘site’, will try loading ‘/usr/pip.conf’
global.index-url=‘https://mirrors.aliyun.com/pypi/simple’
install.trusted-host=‘mirrors.aliyun.com’
我们操作第一个文件(不同系统目录不同文件后缀也不一致)即可
- 创建和修改pip配置文件
cd /etc/xdg/xdg-ubuntu/
sudo mkdir .pip
sudo touch pip.conf
vim pip.conf
将下面的代码拷贝进去
[global]
index-url=http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com