欢迎来到 岁月小筑

一键更换国内云服务器Python pip镜像源至国内Pypi镜像源

前言

为了更方便的为国内的服务器更换Python pip源(就是懒,特别是最近),特意写了一个一键更换pip源脚本,目前只在Centos上测试过,不过理论上Linux系统通用

使用

Centos/Debian/Ubuntu/RHEL通用(请先安装wget这种应该不用我说吧)

wget xiaofd.github.io/pip.sh && bash pip.sh

 

效果图:

一键更换pip源

源代码

#!/bin/bash

function sets()
{
mkdir /root > /dev/null 2>&1
mkdir /root/.pip > /dev/null 2>&1
mv /root/.pip/pip.conf /root/.pip/pip.conf.bak > /dev/null 2>&1
cat << EOF >> /root/.pip/pip.conf
[global]
timeout = 60
index-url = $1
EOF
}

getopts :s: OPT
if [ ! -n "$OPTARG" ];then
  echo "You can use -s with: tuna|ali|ustc|douban to use different source"
  echo "Use Default Setting: Douban Pypi"
  sets "https://pypi.douban.com/simple"
elif [ "$OPTARG" == "tuna" ];then
  echo "Use Tsinghua Pypi"
  sets "https://pypi.tuna.tsinghua.edu.cn/simple"
elif [ "$OPTARG" == "ali" ];then
  echo "Use Aliyun Pypi"
  sets "https://mirrors.aliyun.com/pypi/simple"
elif [ "$OPTARG" == "ustc" ];then
  echo "Use USTC Pypi"
  sets "https://pypi.mirrors.ustc.edu.cn/simple"
fi

echo "The original source has been move to pip.conf.bak"

 

点赞

发表评论

电子邮件地址不会被公开。