https://github.com/pyenv/pyenv

安装依赖

sudo yum -y install gcc make patch gdbm-devel openssl-devel sqlite-devel readline-devel zlib-devel bzip2-devel

如果能直连 github

curl https://pyenv.run | bash

设置环境变量

将下方内容添加到 ~/.bashrc

export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

eval "$(pyenv virtualenv-init -)"

查看版本

pyenv install -l

安装Python版本

CONFIGURE_OPTS="--enable-optimizations" CPPFLAGS=-I/usr/include/openssl LDFLAGS=-L/usr/lib64 pyenv install -v 3.10.0

如果/tmp 目录被挂载微不可执行,会收到报错

$ pyenv install 3.10.0
python-build: TMPDIR=/tmp cannot hold executables (partition possibly mounted with `noexec`)

执行 sudo mount -o remount,exec /tmp 之后继续安装python即可

安装virtualenv

pyenv virtualenv  3.10.0 py310-test

安装过程中的依赖问题

No module named '_ctypes'

No module named '_lzma'

sudo yum install lzma libffi

No module named '_ssl'

先安装 openssl-devel 包,安装后若还有报错,则自行指定 openssl库位置 指定openssl 库位置

libffi