1.更换yum源
备份(官方停止维护,无所谓了),更改配置文件,清除缓存,建立缓存
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=https://mirrors.ustc.edu.cn/centos-vault/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
baseurl=https://mirrors.ustc.edu.cn/centos-vault/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
baseurl=https://mirrors.ustc.edu.cn/centos-vault/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
baseurl=https://mirrors.ustc.edu.cn/centos-vault/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
yum install epel-release -y
2.安装gcc套件
yum install -y gcc
3.解压python源码包
官方镜像站:https://www.python.org/ftp/python/
阿里镜像站:https://mirrors.aliyun.com/python-release/
tar -zxf /opt/software -C /usr/local/src/ ; mv /usr/local/src/Python-3.9.9 /usr/local/src/python
4.安装依赖
yum install gcc libffi-devel python-devel openssl-devel
5.编译
cd /usr/local/src/python
5.1 指定安装目录
./configure --prefix=/usr/local/src/python3
5.2 编译安装
make && make install
6.添加环境变量
echo "PYTHON_HOME=/usr/local/src/python3" >> /etc/profile
echo "PATH=$PATH:$PYTHON_HOME/bin"" >> /etc/profile
7.效果图
ps:
使用追加记录日志make install >> log.txt
只有错误信息会输出到控制台,我捕捉到一个错误:
/usr/local/src/python/Modules/_ctypes/_ctypes.c:107:17: 致命错误:ffi.h:没有那个文件或目录 #include <ffi.h>
,是没有安装依赖造成的
链接:
中科大CentOS-Base.repo