📜  centos install python 3.9 thelinuxterminal.com - Python(1)

📅  最后修改于: 2023-12-03 14:59:54.565000             🧑  作者: Mango

CentOS安装Python 3.9

在CentOS上安装Python 3.9可以使用yum和源码两种方式。本文将为大家介绍这两种方式的操作步骤。

使用yum安装Python 3.9
  1. 打开终端,使用以下命令更新yum:

    sudo yum update -y
    
  2. 安装EPEL源:

    sudo yum install epel-release -y
    
  3. 安装IUS源:

    sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm -y
    sudo yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
    sudo yum install yum-utils -y
    sudo yum-config-manager --enable remi
    sudo yum update -y
    
  4. 安装Python 3.9:

    sudo yum install python39 -y
    
  5. 安装pip:

    sudo yum install python39-pip -y
    
  6. 验证Python和pip:

    python3.9 -V
    pip3.9 -V
    
使用源码安装Python 3.9
  1. 安装依赖:

    sudo yum groupinstall 'Development Tools' -y
    sudo yum install zlib-devel bzip2-devel openssl-devel ncurses-devel \
    sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel -y 
    
  2. 从Python官网下载源码包:

    wget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz
    
  3. 解压源码包并进入目录:

    tar -zxvf Python-3.9.0.tgz
    cd Python-3.9.0
    
  4. 编译并安装:

    ./configure --enable-optimizations
    make -j8
    sudo make altinstall
    
  5. 验证Python和pip:

    python3.9 -V
    pip3.9 -V
    

现在,您已成功在CentOS上安装Python 3.9!