Centos7下源码安装Python3 脚本

源码安装

#安装依赖软件包
install_pkg(){
yum -y install gcc gcc-c++ zlib-devel bzip2-devel openssl-devel  sqlite-devel readline-devel  libffi-devel &>/dev/null
}

#下载软件包
download_pkg(){
cd /tmp
wget https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tar.xz  &>/dev/null
}

#解压安装
tar_pkg(){
cd /tmp
tar -xf Python-3.7.6.tar.xz  &>/dev/null
cd Python-3.7.6
}

#修改文件
change_config(){
sed -ri 's/^#readline/readline/' Modules/Setup.dist
sed -ri 's/^#(SSL=)/\1/' Modules/Setup.dist
sed -ri 's/^#(_ssl)/\1/' Modules/Setup.dist 
sed -ri 's/^#([\t]*-DUSE)/\1/' Modules/Setup.dist 
sed -ri 's/^#([\t]*-L\$\(SSL\))/\1/' Modules/Setup.dist
}

#编译安装
make_makeinstall(){
cd /tmp/Python-3.7.6
./configure --enable-shared &>/dev/null
make && make install  &>/tmp/python_.log
}

#配置共享库文件
lib_config(){
echo "# python3.7 共享库目录" >>  /etc/profile.d/python3_lib.sh
echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib" >>  /etc/profile.d/python3_lib.sh
echo "/usr/local/lib" >> /etc/ld.so.conf.d/python3.conf
ldconfig
source /etc/profile
}

main(){
    install_pkg
    if [ $? -eq 0 ];then
        echo "依赖软件包安装完成"
    else
        break
        echo "依赖软件包安装失败,请检查网络"
    fi

    download_pkg 
     if [ $? -eq 0 ];then
        echo "软件包下载完成"
    else
        break
        echo "软件包下载失败,请检查网络"
    fi

    tar_pkg
     if [ $? -eq 0 ];then
        echo "软件包解压完成"
    else
        break
        echo "软件包解压失败,请安装包是否存在"
    fi
  
    change_config &>/dev/null
   
    make_makeinstall
     if [ $? -eq 0 ];then
        echo "Python安装完成"
    else
        break
        echo "编译安装失败,请查看/tmp/python_.log"
    fi

    lib_config
    
    pip3 -V >/dev/null
    
    if [ $? -eq 0 ];then
        echo "pip3安装完成"
    else
        break
        echo "pip3安装失败,"
    fi

}
main

 

Centos7下源码安装Python3 脚本Centos7下源码安装Python3 脚本 不知名的better 发布了3 篇原创文章 · 获赞 0 · 访问量 38 私信 关注
上一篇:spring发布和接收定制的事件(spring事件传播)[转]


下一篇:BRCM5.02编译六:No package 'zlib' found