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

124次阅读
没有评论

共计 871 个字符,预计需要花费 3 分钟才能阅读完成。

#!/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"

 

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

使用

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

 

效果图:

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

源代码

正文完
 
admin
版权声明:本站原创文章,由 admin 2020-01-13发表,共计871字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)
验证码