CentOS环境下安装Python3

安装相关包,以便后续编译安装python3

$ yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make -y

下载python3源码包

$ cd /usr/local
$ wget https://www.python.org/ftp/python/3.7.15/Python-3.7.15.tgz

解压并安装

$ tar -zxvf Python-3.7.15.tgz
$ cd Python-3.7.15
$ ./configure prefix=/usr/local/python3
$ make && make install

配置python环境变量

vi /etc/profile

# 在profile文件追加下面两行
export PYTHON_HOME=/usr/local/python3/
export PATH=$PYTHON_HOME/bin:$PATH

# 保存并推出,使配置生效
source /etc/profile

验证python
在这里插入图片描述

你可能感兴趣的:(Python,centos,python,linux)