CentOS更新Python環境常用方法如下:
使用包管理器(推薦)
yum
/dnf
,先安裝EPEL倉庫:sudo yum install epel-release # CentOS 7
sudo dnf install epel-release # CentOS 8
sudo yum install python3.10 # CentOS 7
sudo dnf install python3.10 # CentOS 8
python3.10 --version
使用SCL(Software Collections)
sudo yum install centos-release-scl
sudo yum install rh-python38
scl enable rh-python38 bash # 臨時切換環境
python --version
使用pyenv(靈活管理多版本)
curl https://pyenv.run | bash
echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init --path)"' >> ~/.bashrc
source ~/.bashrc
pyenv install 3.9.7
pyenv global 3.9.7
python --version
手動編譯安裝(需處理依賴)
wget https://www.python.org/ftp/python/3.10.12/Python-3.10.12.tgz
tar xzf Python-3.10.12.tgz
cd Python-3.10.12
./configure --enable-optimizations
sudo make altinstall
python3.10 --version
注意事項:
pyenv
或SCL,避免手動修改系統默認Python。