可以切换到阿里云yum源:
sudo yum -y update
必备包
sudo yum -y install wget yum-utils gcc openssl-devel bzip2-devel libffi-devel zlib zlib-devel
cd /tmp/
wget https://www.python.org/ftp/python/3.8.6/Python-3.8.6.tgz
tar xzf Python-3.8.6.tgz
cd Python-3.8.6
sudo ./configure --prefix=/opt/python38 --enable-optimizations --with-lto --with-system-ffi --with-computed-gotos --enable-loadable-sqlite-extensions
sudo make -j "$(nproc)"
sudo make altinstall
如果提示:
/usr/local/bin/python: can't decompress data; zlib not available
安装目录/Modules/Setup ,将#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
的注释去掉。
sudo ln -s /opt/python38/bin/python3.8 /opt/python38/bin/python3
sudo ln -s /opt/python38/bin/python3.8 /usr/bin/python38
sudo ln -s /opt/python38/bin/python3.8 /opt/python38/bin/python
sudo ln -s /opt/python38/bin/python3.8-config /opt/python38/bin/python-config
sudo ln -s /opt/python38/bin/pydoc3.8 /opt/python38/bin/pydoc
sudo ln -s /opt/python38/bin/idle3.8 /opt/python38/bin/idle
sudo ln -s /opt/python38/bin/pip3.8 /opt/python38/bin/pip3
sudo ln -s /opt/python38/bin/pip3.8 /opt/python38/bin/pip
sudo /opt/python38/bin/python -m venv /opt/pyenv
source /opt/pyenv/bin/activate