Centos7安装Python3.9

mtain 2023年09月11日 178次浏览

安装

1. 下载

wget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz

2. 解压编译安装

# 安装编译工具
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make


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

3. 创建软连接

ln -s /usr/local/python3/bin/python3.9 /usr/bin/python
ln -s /usr/local/python3/bin/pip3.9 /usr/bin/pip

4. 配置环境变量

vi /etc/profile

export PYTHON_HOME=/usr/local/python3
export PATH=$PYTHON_HOME/bin:$PATH

source /etc/profile

5. 验证安装

python3 --version

6. 配置pip镜像源

vi ~/.pip/pip.conf
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/