温馨提示×

centos怎样卸载python

小樊
36
2026-10-06 06:55:30
栏目: 编程语言

在 CentOS 上不建议直接卸载系统自带的 Python,因为很多系统管理工具(如 yum、dnf、firewalld)都依赖 Python。如果强行卸载,可能导致系统无法使用。

下面分情况说明:


一、⚠️ 重要警告(先读)

  • CentOS 7:系统依赖 Python 2
  • CentOS 8 / Stream:系统依赖 Python 3
  • 不要执行:
    rpm -e python
    
    或
    rm -rf /usr/bin/python
    

二、只是想“清理自己装的 Python”

1️⃣ 查看已安装的 Python

rpm -qa | grep python

或

which python3
python3 --version

2️⃣ 卸载通过 yum 安装的 Python

yum remove python3

(仅在你确认不是系统核心依赖时)


3️⃣ 卸载源码编译安装的 Python

如果你是这样装的:

./configure
make
make install

一般只能手动删除:

rm -rf /usr/local/python3
rm -f /usr/local/bin/python3

三、正确做法(推荐)

✅ 使用虚拟环境(不卸载系统 Python)

python3 -m venv myenv
source myenv/bin/activate

✅ 多版本管理(推荐)

  • pyenv
  • conda

四、如果已经误删 Python(救援)

CentOS 7

yum reinstall python

CentOS 8

dnf reinstall python3

如果 yum/dnf 已坏,需用:

rpm -ivh --force python*.rpm

五、请告诉我

  • CentOS 版本(cat /etc/centos-release)
  • Python 版本
  • 你是想彻底删掉,还是只换版本

我可以给你安全的具体命令。

0 踩