Linux下安装python3.7.9

发布时间 2023-06-11 14:38:59作者: 人间丶迷走
  • 操作系统与原有python

    [pythondemo@localhost ~]$ cat /etc/centos-release
    CentOS Linux release 7.4.1708 (Core)
    
    
    [pythondemo@localhost ~]$ python
    Python 2.7.5 (default, Aug  4 2017, 00:39:18)
    [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
    
  • 下载python 3.7.9

    curl https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tgz
    
  • 安装依赖

    yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
    
  • 解压压缩包

    tar -zxvf Python-3.7.9.tgz
    
  • 把解压后的python移到/usr/local

    mv Python-3.7.9 /usr/local
    # 进入解压后的目录
    cd /usr/local/bin/python3.7.9
    
  • 编译python3.7.9

    # 配置
    ./configure
    # 编译
    make
    # 安装
    make install
    
  • 新建软链接

    # 查看原有软链接
    ll -d /usr/bin/python
    lrwxrwxrwx. 1 root root 7 Aug  4  2020 /usr/bin/python -> python2
    # 删除原有的软链接
    rm -rf /usr/bin/python
    # 新建软链接
    ln -s /usr/local/bin/python3.7.9 /usr/bin/python
    
  • 安装完成

    [pythondemo@localhost ~]$ python3
    Python 3.7.9 (default, Jun 11 2023, 21:54:07)
    [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> quit()