ubuntu20.04 server服务器版配置pip国内源(python3)

python 版本

ubuntu20.04 server服务器默认安装的是python3.8,可通过下面命令查看:

python

pip3的配置目录

新版 pip3 配置目录

~/.config/pip/pip.conf

现代 Linux 统一遵循 XDG Base Directory 规范:
用户自定义配置,统一放在:

~/.config/应用名/

老版 pip3 配置目录

~/.pip/pip.conf

配置pip3国内源

# 先删掉旧的无效配置
rm -rf ~/.pip

# 创建官方标准目录
mkdir -p ~/.config/pip

# 写入阿里云源
cat > ~/.config/pip/pip.conf << EOF
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
trusted-host = mirrors.aliyun.com
EOF

验证

pip3 config list

显示下面内容,说明成功:

global.index-url='https://mirrors.aliyun.com/pypi/simple/'
global.trusted-host='mirrors.aliyun.com'

原文出处:/show_1GW31pMoAfXb.html