> For the complete documentation index, see [llms.txt](https://hezhiqiang.gitbook.io/about-the-author/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hezhiqiang.gitbook.io/about-the-author/yun-wei-huan-jing-da-jian/centos-an-zhuang-python3.8.1.md).

# 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 %}

![](/files/-LxUjwtzx_R1pEnnpPAi)

```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
```

![](/files/-LxUl1f8KciHVO-1qbUh)

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