openEuler 20.04 TLS3 是基于 centos8.5 stream的套皮,所以编译安装python的难度很低,与低版本不同的是注意补充下uuid和libnsl的库,不然configure构建出来的makefile会缺少_uuid、nis这俩模块。其他与老版本一致。
bash
#! /bin/bash
# filename: python-instaler.sh
SOURCE_PATH=/usr/local/source
# 下载源码包
mkdir -p $SOURCE_PATH
curl -o $SOURCE_PATH/Python-3.11.9.tgz https://www.python.org/ftp/python/3.11.9/Python-3.11.9.tgz
# 解压
tar zxvf $SOURCE_PATH/Python-3.11.9.tgz -C $SOURCE_PATH
# 安装编译依赖
yum install -y gcc make
# 安装依赖
dnf install -y \
openssl openssl-devel openssl-static \
bzip2 bzip2-devel \
ncurses ncurses-devel \
readline readline-devel \
xz lzma xz-devel \
sqlite sqlite-devel \
gdbm gdbm-devel \
expat-devel \
tk tk-devel \
tcl tcl-devel \
libffi libffi-devel \
libnsl libnsl2-devel \
uuid libuuid-devel
# 编译安装
cd $SOURCE_PATH/Python-3.11.9
mkdir -p /usr/local/python/python3.11.9
./configure --enable-shared --prefix=/usr/local/python/python3.11.9 --enable-optimizations
make && make install
# 添加环境变量
echo 'export PATH="$PATH:/usr/local/python/python3.11.9/bin"' >> /etc/profile
cp -f libpython3.11.so.1.0 /lib64
cd -