其实在Centos上安装Python3很容易,直接使用YUM方式安装完事
一句话完事
yum install python3 -y#注意:安装Py版本为3.6,默认安装pip3
但是部分镜像的YUM不全或者repo未配置等等,这种情况就需要手动来编译 .
博主前些日子白嫖了个HCaas的容器虚拟机,想跑一下爬虫,结果乱码,有点难噶
有需要的可以去嫖一下,有100的代金券,【 HCaas 】
本来想自己写一个来着,但是想了一下,没必要重复造轮子,
从别的地儿找个轮子算了,于是看到了这篇代码,我Jio的还行,做个备份。
#!/bin/bash PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin export PATH # Check if user is root if [ $(id -u) != "0" ]; then echo "Error: You must be root to run this script, please use root to initialization OS." exit 1 fi version="3.7.4" echo "Please enter the version number you need:" read -p "(Default version: 3.7.4):" version if [ "$version" = "" ];then version="3.7.4" fi name="Python" pyfile="$name-$version.tgz" check_ver=`echo $version|awk '{printf ("%3.1f\n",$1)}'` dir="/usr/local/python3" # Check if user is root if [ $(id -u) != "0" ]; then echo "Error: You must be root to run this script, please use root to install" exit 1 fi rpm=`rpm -qa libffi-devel|awk -F "-" '{print $1}'` if [ -z $rpm ];then yum -y install wget gcc gcc-c++ make openssl-devel bzip2-devel libffi-devel else echo -e "\033[40;31m libffi [found]\033[40;37m" fi if [ -e $dir ];then rm -fr /usr/local/python3 rm -rf /usr/bin/python3 rm -rf /usr/bin/pip3 else echo -e "\033[40;31m python [no found]\033[40;37m" fi if [ -s $pyfile ];then echo -e "\033[40;31m $pyfile [found]\033[40;37m" else wget https://www.python.org/ftp/python/$version/$pyfile tar zxf $pyfile fi cd $name-$version ./configure --prefix=/usr/local/python3 --enable-optimizations make altinstall if [ "$check_ver" = "3.7" ];then ln -s /usr/local/python3/bin/python3.7 /usr/bin/python3 ln -s /usr/local/python3/bin/pip3.7 /usr/bin/pip3 elif [ "$check_ver" = "3.8" ];then ln -s /usr/local/python3/bin/python3.8 /usr/bin/python3 ln -s /usr/local/python3/bin/pip3.8 /usr/bin/pip3 fi if [ -d /root/.pip ];then echo -e "\033[40;31m file is [found]\033[40;37m" else mkdir ~/.pip cat > ~/.pip/pip.conf <<EOF [global] index-url = https://pypi.doubanio.com/simple/ [install] trusted-host=pypi.doubanio.com disable-pip-version-check = true timeout = 6000 EOF fi pip3 install --upgrade pip echo -e "\nInstalled Python and pip version is ... " python3 -V && pip3 -V echo -e "\033[32m \nInstall Successfully! \033[0m"
以上部分内容来自[ https://blog.slogra.com/post-767.html ]
发表评论