centos7 安裝 python3.12

huelse發表於2024-06-18

準備工作

  • yum install centos-release-scl
  • scl enable devtoolset-11 bash
  • wget https://www.python.org/ftp/python/3.12.4/Python-3.12.4.tgz

編譯

注意是在 scl 環境下進行的,gcc 版本過低的環境會導致編譯失敗

tar -zxf Python-3.12.4.tgz
cd Python-3.12.4
./configure --prefix=/usr/local/python3 --enable-optimizations --enable-shared --with-ssl
make && make install

連結

ln -s /usr/local/python3/bin/python3.12 /usr/local/bin/python3
ln -s /usr/local/python3/bin/pip3.12 /usr/local/bin/pip3
echo '/usr/local/python3/lib' >> /etc/ld.so.conf.d/python.conf
ldconfig

測試

python3 -V
pip3 -V

相關文章