CentOS7编译安装Python3.9.2

  • 安装前准备(准备编译环境)
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel libffi-devel gcc make
  • 获取Python3.9.2源码
#获取源码
wget https://www.python.org/ftp/python/3.9.2/Python-3.9.2.tgz

#解压
tar -xvf Python-3.9.2.tgz -C /usr/local/src/
  • 安装Python3.9
#进入源码目录
cd /usr/local/src/Python-3.9.2/
#指定安装目录
./configure --prefix=/usr/local/python3
#编译安装
make && make install
  • 配置环境变量
#编辑/etc/profile,在尾部添加如下代码:
PATH=/usr/local/python3/bin:$PATH
export PATH

#使用source命令重新加载/etc/profile
source /etc/profile

#查看安装的python版本
python3 --version

你可能感兴趣的:(CentOS7编译安装Python3.9.2)