centos 升级python3.9.7

更新python3之前需要更新依赖 否则make install时会失败

  1. 更新一下yum阿里云的源
    cd /etc/yum.repos.d/
    
    mkdir bak
    
    mv * bak
    
    wget http://mirrors.aliyun.com/repo/Centos-7.repo
    
    wget http://mirrors.aliyun.com/repo/epel-7.repo
  2. 在1点基础上安装依赖
    yum -y install zlib-devel bzip2-devel openssl-devel openssl-static ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel lzma gcc
    
    yum -y groupinstall "Development tools"
  3. 下载python3.9.7
    
    ​
    wget https://www.python.org/ftp/python/3.9.7/Python-3.9.7.tgz
    
    ​
    其他版本查看https://www.python.org/ftp/python/
  4. 解压
    tar -vxzf  Python-3.9.7.tgz
    
    cd Python-3.9.7

  5. 安装编译
    ./configure --prefix=/usr/local/python-3.9
    
    
    make && make install

    如果这里失败也可再执行1、2

  6. 环境变量配置

    vi /etc/profile

    在最下边输入 保存退出

    export PYTHON_HOME=/usr/local/python3.9
    export PATH=${PYTHON_HOME}/bin:$PATH
    
  7. 使得配置的环境变量立即生效:

    source /etc/profile
    

你可能感兴趣的:(学习笔记,centos,服务器,python)