1.前置工作
1.1 下載地址
https://www.python.org/ftp/python/3.10.15/Python-3.10.15.tgz
1.2 安裝系統依賴
# 安裝依賴
yum install -y gcc zlib-devel openssl-devel bzip2-devel
# 上⾯的如果不⾏,執⾏下⾯的(注:如果沒有openssl-devel需要⼿動安裝)
yum install -y gcc zlib-devel openssl-devel bzip2-devel --nogpgcheck
2.部署Python
# 解壓並開始編譯
tar -zxvf $HOME/setup/Python-3.10.15.tgz -C $HOME/setup
cd $HOME/setup/Python-3.10.15
# 開始編譯安裝
./configure --prefix=$HOME/python3.10.15 --enable-shared --enable-loadable-sqlite-extensions
make -j8
make altinstall
3.測試Python
$HOME/python3.10.15/bin/python3.10
# 解決⽅法,配置環境變數
/root/python3.10.15/bin/python3.10: error while loading shared libraries:
libpython3.10.so.1.0: cannot open shared object file: No such file or directory
4.配置環境
echo "export LD_LIBRARY_PATH=\"$HOME/python3.10.15/lib:\$LD_LIBRARY_PATH\"" >> $HOME/.bashrc
echo "export PATH=\"$HOME/python3.10.15/bin:\$PATH\"" >> $HOME/.bashrc
source $HOME/.bashrc
# 建立軟連線(注意軟連線版本)
ln -s $HOME/python3.10.15/bin/python3.9 $HOME/python3.9.0/bin/python
ln -s $HOME/python3.10.15/bin/pip3.9 $HOME/python3.9.0/bin/pip
5.驗證Python
python -V
Python 3.10.15
pip -V
pip 56.2.3 from /root/python3.10.15/lib/python3.10/site-packages/pip (python 3.10)