一、安装编译相关依赖

  1. $yum update
  2. $yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel
  3. sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel -y

二、 下载最新的源码包

从Python官方源中下载最新的源码包,或者从国内镜像源中下载
https://www.python.org/ftp/python/

  1. [root@wuhu ~]# cd /usr/local/src
  2. [root@wuhu src]# wget https://www.python.org/ftp/python/3.10.0/Python-3.10.0.tar.xz
  3. [root@wuhu src]# tar -xvJf Python-3.10.0.tar.xz

三、编译安装

  1. mkdir /usr/local/python3
  2. cd Python-3.10.0/
  3. ./configure --prefix=/usr/local/python3
  4. make && make install

四、建立软连接或者添加PATH

  1. ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3
  2. ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3

五、验证安装

  1. [root@dcoker-test Python-3.10.0]# python3
  2. Python 3.10.0 (default, Jan 20 2022, 15:58:13) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
  3. Type "help", "copyright", "credits" or "license" for more information.
  4. >>>