centos7(6)脚本安装python3.7环境(含ssl和pip)

最近想在集群跑pyspark,需要每台机器配置python3环境.众所周知,centos的openssl版本太低,装py3.7最好先解决ssl问题,装起来挺费时间的.所以写个简易脚本方便安装.

#!/bin/bash
# 请确保openssl-1.1.1d.tar.gz,Python-3.7.5.tgz的tar.gz包存放在当前目录下

echo "请确保openssl-1.1.1d.tar.gz,Python-3.7.5.tgz的tar.gz包存放在当前目录下,按Enter继续"
read
yum install -y zlib zlib-dev openssl-devel sqlite-devel bzip2-devel libffi libffi-devel gcc gcc-c++

echo "------------安装openssl----------"
tar -zxf openssl-1.1.1d.tar.gz
if [ $? -ne 0 ];then
    echo "解压错误,请检查安装包"
    exit 1
fi
cd openssl-1.1.1d
./config --prefix=/usr/local/openssl shared zlib
make && make install
echo "------------完成安装openssl----------"

# 配置 openssl 共享库
# 检验 openssl-1.1.1 是否已加入共享库,存在libssl.so.1.1就可以
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf.d/openssl.conf
ldconfig
ldconfig -v | grep ssl
# read
cd ..
echo "------------安装python3.7----------"
tar -zxf Python-3.7.5.tgz
if [ $? -ne 0 ];then
    echo "解压错误,请检查安装包"
    exit 1
fi
cd Python-3.7.5
./configure --prefix=/usr/local/python37 --with-openssl=/usr/local/openssl
make && make install
echo "------------完成安装python3.7----------"

read -p "是否创建pyhon3的软链接(输入Y|y确认)" cmd
if [ "$cmd" == 'Y' ] || [ "$cmd" == 'y' ];then
    echo "要创建!!!"
    ln -s /usr/local/python37/bin/python3.7 /usr/bin/python3.7
    ln -s /usr/local/python37/bin/python3.7 /usr/bin/python3
    ln -s /usr/local/python37/bin/pip3.7 /usr/bin/pip3.7
    ln -s /usr/local/python37/bin/pip3.7 /usr/bin/pip3
fi

echo "当前的python3版本信息:"
python3 -V

感谢此文提供的方法,要比export LD_LIBRARY_PATH=$$/openssl/lib的方法更方便稳定

https://blog.51cto.com/tchuairen/2435472

你可能感兴趣的:(python)