Centos 7 编译安装python3.6

#!/bin/bash
#一键部署python 3 系列开发环境,编译安装成功需要大约20~30分钟,请耐心等候
#请将下载好的python安装包放到/root/ 目录下
#安装包下载地址:https://www.python.org/ftp/python/3.6.4/

Python_Path(){
        #创建python3链接
        Python_Name=`ls /usr/local/python3/bin/|grep "python3\.[0-9]$"`
        ln -s /usr/local/python3/bin/${Python_Name} /usr/bin/python3
        if [ $? -ne 0 ];then
                echo "python 链接失败"
                exit 1
        fi
        
        #创建pip3链接
        ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
        if [ $? -ne 0 ];then
                echo "pip3 链接失败"
                exit 1
        else
                pip3 -V >/dev/null && pip3 install --upgrade pip || echo "pip3 更新异常"
                pip3 install pymysql || echo "pip3 无法正常安装python pymysql库" && exit 1
        fi
}

#检测python 3 系列安装包
Python_Zip_Name=`ls /root/ |grep "^Python-3.*\.tgz$"`
if [ $? -ne 0 ];then
         echo "python 3 系列安装包不存在,请检查/root/目录下是否存在"
         exit 1
else
        echo "安装编译环境"
        yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel>/dev/null
        yum groupinstall 'Development Tools' -y >/dev/null
        if [ $? -ne 0 ];then
                echo "安装python依赖环境失败"
                exit 1
        else
                echo "安装python依赖环境成功"
        fi
fi

#解压缩-python3压缩包
tar -zxf /root/${Python_Zip_Name}
Python_Unzip_Name=`ls /root/ |grep "Python-.*[0-9]$"`

#编译安装python
cd /root/${Python_Unzip_Name}
./configure --prefix=/usr/local/python3 --enable-optimizations
if [ $? -ne 0 ];then
        echo "python 3 初始化配置失败"
        exit 1
else
        echo "python 3 初始化配置成功"
        #编译安装
        make && make install
        if [ $? -ne 0 ];then
                echo "python 3 编译安装失败"
                exit 1
        else
                echo "python 3 编译安装成功"
                #调用函数
                Python_Path
        fi
fi

 

发布了5 篇原创文章 · 获赞 0 · 访问量 1143
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览