安装
apt install python3-pip
配置
用户级设置
mkdir -p ~/.pip
touch ~/.pip/pip.conf
tee ~/.pip/pip.conf <<-'EOF'
[global]
index-url=https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=https://mirrors.aliyun.com/
EOF
这里,我们配置了pip的国内镜像源为阿里云镜像源,如果想用华为镜像源,可以如下配置。
mkdir -p ~/.pip
touch ~/.pip/pip.conf
tee ~/.pip/pip.conf <<-'EOF'
[global]
index-url = https://mirrors.huaweicloud.com/repository/pypi/simple/
[install]
trusted-host=https://mirrors.huaweicloud.com/
EOF
另外,清华源质量也不错,配置如下:
mkdir -p ~/.pip
touch ~/.pip/pip.conf
tee ~/.pip/pip.conf <<-'EOF'
[global]
index-url=https://pypi.tuna.tsinghua.edu.cn/simple/
[install]
trusted-host=https://pypi.tuna.tsinghua.edu.cn/
EOF
全局级设置
上面,我们基于用户级做了配置,如果我们要基于全局用户做配置,也可以如下配置。
sudo mkdir -p /etc/pip
sudo touch /etc/pip/pip.conf
sudo tee /etc/pip/pip.conf <<-'EOF'
[global]
index-url=https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=https://mirrors.aliyun.com/
EOF
查看配置
设置好配置以后,如果要查看配置,可以用下面命令
pip config list
参考文献