# CentOS 安装 Python3.8.X

#### 博客作者：联系请[点击](https://hezhiqiang.gitbook.io/about-the-author/lian-xi-zuo-zhe)，搬运不易，希望请作者喝咖啡，可以点击联系[博客作者](https://hezhiqiang.gitbook.io/about-the-author/lian-xi-zuo-zhe)

## 概述

这里，我就准备在我的 CentOS 下安装一个 Python3 的最新版本，目前的最新稳定版本是 Python3.8.1，所以我就决定安装这一个版本的，但是，需要说明的是，我不准备覆盖原来的 Python2.7，也就是说，最终在我的系统中，会有两个 Python 的版本，互不干扰。

## 下载 Python3.8.1 源代码

Python 提供了一个 FTP 地址，在这个 FTP 你可以下载的各个版本的 Python 源代码：

{% embed url="<https://www.python.org/ftp/python/>" %}

```bash
wget https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tgz 
tar -zvxf Python-3.8.1.tgz && cd Python-3.8.1/
```

### 编译前准备

{% hint style="info" %}
&#x20;因为编译 Python 源代码需要依赖于很多工具，所以得先准备一下：
{% endhint %}

```bash
yum --exclude=kernel* update -y
yum groupinstall -y 'Development Tools'
yum install -y gcc openssl-devel bzip2-devel libffi-devel
```

### 编译安装 Python3.8.1

{% hint style="success" %}
出现如下图所示表示编译成功
{% endhint %}

![](https://139036132-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lx53lMutrsyPUks5pJf%2F-LxUYd0rwrLDQYEjHt7D%2F-LxUjwtzx_R1pEnnpPAi%2Fimage.png?alt=media\&token=4d6b704f-d382-4d5f-a55f-fd914f879d97)

```bash
./configure prefix=/usr/local/python3 --enable-optimizations
make && make install
export PATH=$PATH:/usr/local/python3/bin/
```

### 测试安装效果

{% hint style="info" %}
要想测试是否正确安装，并且可以正确使用 Python3.8.1 和 pip3，我这里采用 Virtualenv 的方式进行验证：
{% endhint %}

```bash
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3.8 get-pip.py
python3 -m pip install virtualenv
python3 -m virtualenv venv
source venv/bin/activate
python --version
```

![](https://139036132-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lx53lMutrsyPUks5pJf%2F-LxUYd0rwrLDQYEjHt7D%2F-LxUl1f8KciHVO-1qbUh%2Fimage.png?alt=media\&token=7d3ad7ab-60a6-4e02-a1bc-bd2bdbafa554)

{% hint style="success" %}
OK，到此就表示一切都安装正常了，可以和其他环境一样使用最新稳定版的 Python3 了。
{% endhint %}
