Centos7编译安装Python3.10

2023-04-18  本文已影响0人  sunfkny
#!/bin/bash
set -e
# Extract Python minor and build version
PYTHON_VERSION="3.10.12"
PYTHON_MINOR_VERSION="$(echo $PYTHON_VERSION | cut -d'.' -f 2)"
PYTHON_BUILD_VERSION="$(echo $PYTHON_VERSION | cut -d'.' -f 3)"
DOWNLOAD_PREFIX=https://registry.npmmirror.com/-/binary/python/$PYTHON_VERSION
# DOWNLOAD_PREFIX=https://www.python.org/ftp/python/$PYTHON_VERSION

# Check if CentOS 7
if [[ "$(rpm -E %{rhel})" == "7" ]]; then
    echo "CentOS 7 detected, install openssl11"
    yum -y install openssl11 openssl11-devel
    export CFLAGS=$(pkg-config --cflags openssl11)
    export LDFLAGS=$(pkg-config --libs openssl11)
else
    echo "Not CentOS 7, skip openssl11"
fi

# Install dependencies
yum -y install wget epel-release gcc zlib zlib-devel libffi libffi-devel readline-devel openssl-devel mysql-devel sqlite-devel

# Download and install Python
cd /root
wget $DOWNLOAD_PREFIX/Python-$PYTHON_VERSION.tgz -O Python-$PYTHON_VERSION.tgz
tar -xzf Python-$PYTHON_VERSION.tgz
cd /root/Python-$PYTHON_VERSION
./configure --with-ssl --enable-loadable-sqlite-extensions
make -j$(nproc) && make altinstall
alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.$PYTHON_MINOR_VERSION 0
python3 -V

上一篇下一篇

猜你喜欢

热点阅读