> ## Content Index
> Fetch the complete content index at: https://sgpublic.xyz/llms.txt
> Use this file to discover other available public pages before exploring further.

# WSL CentOS 7 安装 Python 3.10.0
- URL: https://sgpublic.xyz/p/2021/12/6aac9cb1810a4800015335ee/
- Published: 2021-12-04T14:02:20.000Z
- Updated: 2021-12-04T14:02:20.000Z
- Author: Haven Madray
- Tags: 桌面与终端, Windows/WSL, Python, #wp-post

> 参考文章  
>  
> \- [CentOs 7 下安装python3\_猫腻的博客-CSDN博客](https://blog.csdn.net/m0%5F49969111/article/details/115299506?ref=sgpublic.xyz)  
> \- [在 CentOS 上编译安装 Python 3 - 知乎 (zhihu.com)](https://zhuanlan.zhihu.com/p/418309354?ref=sgpublic.xyz)

CentOS 7 自带 Python 2.7.5，但我们需要的是 Python 3.10.0。我们需要先按安装依赖。

安装 yum-utils：

```
yum install yum-utils
```

然后利用它提供的命令 yum-builddep 来安装当前系统中缺失的 Python 依赖软件：

```
yum-builddep python3
```

我所使用的 WSL CentOS 7 镜像没有安装 pip，所以需要安装。

```
yum -y install epel-release
yum install python-pip
```

下载 python-3.10.0 源码包

```
curl -O https://www.python.org/ftp/python/3.10.0/Python-3.10.0.tgz
```

解压

```
tar zxf Python-3.10.0.tgz
```

进入文件夹 Python-3.10.0

```
cd Python-3.10.0
```

执行配置文件

```
./configure --enable-optimizations --prefix=/usr/local/python/python-3.10.0
```

编译并安装

```
make && make install
```

设置环境变量，在目录 /etc/profile.d/ 下新建一个文件，此处命名为 python.sh，在文件中写入：

```
export PATH=/usr/local/python/python-3.10.0/bin:$PATH
```

使配置文件立即生效

```
source /etc/profile.d/python.sh
```

检查 Python3 版本

```
python3 -V
```

检查 pip 版本

```
pip3 -V
```