解决方案:
步骤 1:修复无效的failovermethod配置
bash
复制
下载
sudo sed -i '/failovermethod=priority/d' /etc/yum.repos.d/CentOS-epel.repo
此命令删除所有包含 failovermethod=priority 的行。
步骤 2:切换 CentOS 仓库到归档站点(vault.centos.org)
由于 CentOS 8 已停止支持,需将仓库地址手动修改为归档站点:
bash
复制
下载
# 备份原有仓库配置
sudo mkdir -p /etc/yum.repos.d/backup
sudo mv /etc/yum.repos.d/CentOS*.repo /etc/yum.repos.d/backup/
# 创建新的仓库配置文件
sudo tee /etc/yum.repos.d/CentOS-vault.repo > /dev/null <<'EOF'
[baseos]
name=CentOS Linux $releasever - BaseOS (vault)
baseurl=http://vault.centos.org/centos/8.5.2111/BaseOS/$basearch/os/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
enabled=1
[appstream]
name=CentOS Linux $releasever - AppStream (vault)
baseurl=http://vault.centos.org/centos/8.5.2111/AppStream/$basearch/os/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
enabled=1
[extras]
name=CentOS Linux $releasever - Extras (vault)
baseurl=http://vault.centos.org/centos/8.5.2111/extras/$basearch/os/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
enabled=1
EOF
注意:
这里使用 CentOS 8 最终版本 8.5.2111,如需其他版本,请替换 URL 中的版本号。
如果系统版本不是 8.5.2111,可通过 cat /etc/redhat-release 查看实际版本。
步骤 3:清理缓存并重新安装
bash
复制
下载
# 清理 DNF 缓存
sudo dnf clean all
# 重建元数据缓存
sudo dnf makecache
# 安装所需软件
sudo dnf install -y python3-pip python3-virtualenv python3-devel python3-pandas git curl
验证安装
bash
复制
下载
python3 --version # 检查 Python 3
pip3 --version # 检查 pip
virtualenv --version # 检查 virtualenv