CentOS7在线编译安装Python3

在线编译安装脚本

该脚本的版本号是3.6.8,可以根据需要选择对应的版本进行编译安装

#!/bin/bash
pythonVersion=3
echo "Need to install python version above 3"

# 检测是否安装python3
isPythonInstall=`python3 -V 2>&1|awk '{print $2}'|awk -F '.' '{print $1}'`
echo "The detected python version is $isPythonInstall"


if [ $isPythonInstall -ge $pythonVersion ]
then
  echo '-------------无需安装python3运行环境---------------'
else
  echo '-------------开始安装python3运行环境---------------'
#创建一个python3目录
mkdir /home/tuners/python3
#将安装包复制到 
cp -r /home/tuners/python/Python-3.6.8.tgz /home/tuners/python3/
cd /home/tuners/python3
#下载python3.6.8安装包
#wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz
#下载完成之后,将安装包解压到当前目录:
tar xvf Python-3.6.8.tgz
#安装依赖包
yum -y install vim unzip net-tools && yum -y install wget && yum -y install bzip2 && yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel && yum -y install libglvnd-glx && yum -y install gcc gcc-c++
#先进入Python3目录下的Python-3.6.8目录:
cd Python-3.6.8
#指定python3安装路径:
./configure --prefix=/usr/local/python3.6
#编译+安装
make && make install
#添加python3软链接:
ln -s /usr/local/python3.6/bin/python3.6 /usr/bin/python3
#添加pip3软链接:
ln -s /usr/local/python3.6/bin/pip3 /usr/bin/pip3
echo '--------------安装成功,版本号:-----------------'
python3 --version
echo '--------------安装程序运行所需的依赖包:-----------------'
pip3 install --upgrade pip
pip3 install requests -i https://pypi.doubanio.com/simple
pip3 install paho-mqtt -i https://pypi.doubanio.com/simple
pip3 install pillow -i https://pypi.doubanio.com/simple
fi

你可能感兴趣的:(python)