Centos7在线快速安装python3

  1. 首先安装依赖包:
yum -y install gcc zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel libffi-devel xz-devel
  1. 使用国内镜像源下载Python源码(以Python 3.8.12为例):
wget https://mirrors.huaweicloud.com/python/3.8.12/Python-3.8.12.tgz
# 如果华为源访问慢,可以尝试清华源:
# wget https://mirrors.tuna.tsinghua.edu.cn/python/3.8.12/Python-3.8.12.tgz
  1. 解压安装:
tar -xf Python-3.8.12.tgz
cd Python-3.8.12
./configure --prefix=/usr/local/python3
make && make install
  1. 创建软链接:
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
  1. 配置pip国内源,提升包下载速度:
mkdir ~/.pip
cat > ~/.pip/pip.conf << EOF
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn
EOF
  1. 验证安装:
python3 --version
pip3 --version

这样就完成了Python3的安装,并配置了国内镜像源,可以正常使用pip安装包了。

你可能感兴趣的:(Linux系统运维,linux,python)