centos7.9 升级python3.9

centos7.9 升级python3.9

  • 卸载自带python
  • 安装新版
  • 验证安装成功
  • CentOS7误删python2.7及yum后解决办法

在虚拟环境中升级python 不可行,只能系统中重新装python

卸载自带python

rpm -qa | grep python3 | xargs rpm -e --allmatches --nodeps 

//强制卸载自带的python以及相关联的程序

whereis python3 | xargs rm -rf 

//删除所有与python相关的残余文件

安装新版

wget https://www.python.org/ftp/python/3.9.7/Python-3.9.7.tar.xz
tar xvf Python-3.9.7.tar.xz
yum groupinstall "Development Tools" -y
yum install openssl-devel libffi-devel bzip2-devel -y

验证

gcc --version
cd Python-3.9.7/
./configure --enable-optimizations
make altinstall

验证安装成功

python3.9 --version
pip3.9 --version

软软连接在新打开的session窗口就起作用了,当前窗口,仍然报错-bash: /usr/local/bin/python: 没有那个文件或目录,可以先删除没用的python软连接

ln -s /usr/local/bin/python3.9 /usr/bin/python3

CentOS7误删python2.7及yum后解决办法

从 http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/下载系统的包

wget http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/lvm2-python-libs-2.02.187-6.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/libxml2-python-2.9.1-6.el7.5.x86_64.rpm
wget http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages//python-libs-2.7.5-89.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/python-ipaddress-1.0.16-2.el7.noarch.rpm
wget http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/python-backports-1.0-8.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm
wget http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/python-2.7.5-89.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
wget http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/python-urlgrabber-3.10-10.el7.noarch.rpm
wget http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/python-setuptools-0.9.8-7.el7.noarch.rpm
wget http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/python-kitchen-1.1.1-5.el7.noarch.rpm
wget http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/python-chardet-2.2.1-3.el7.noarch.rpm
wget http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/rpm-python-4.11.3-45.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/yum-utils-1.1.31-54.el7_8.noarch.rpm
wget http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm
wget http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/yum-plugin-aliases-1.1.31-54.el7_8.noarch.rpm
wget http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/yum-plugin-protectbase-1.1.31-54.el7_8.noarch.rpm
wget http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm
wget http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/lvm2-libs-2.02.187-6.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/rpm-4.11.3-45.el7.x86_64.rpm
rpm -Uvh --replacepkgs python*.rpm
rpm -Uvh --replacepkgs libxml2-python*.rpm --nodeps --force
rpm -Uvh --replacepkgs yum*.rpm
rpm -Uvh --replacepkgs lvm2-python-libs*.rpm --nodeps --force
rpm -Uvh --replacepkgs rpm-python*.rpm yum*.rpm
rpm -Uvh rpm-4.11.3-45.el7.x86_64.rpm --nodeps
rpm -Uvh --replacepkgs rpm-python*.rpm yum*.rpm --nodeps
cd /usr/bin/
vi yum #第一行改为 #!/usr/bin/python2.7  

参考连接2
参考连接3

你可能感兴趣的:(笔记,python)