问题描述
最近需要在linux上部署项目,安装python3。
为了不出那么多错,把centos自带的python2卸载了。
谁知道之后yum和pip都不能正常使用了。
经过一番搜索,才知道系统中多处需要python2,所以需要把python2重新装上。
解决方案
- 创建目录用来存放rpm包:
mkdir /usr/local/src/python
- 查看系统版本和位数:
- 系统版本
或lsb_release -a
cat /etc/redhat-release
- 查看位数
getconf LONG_BIT
- 进入目录,使用wget分别下载python以及yum的rpm包
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/lvm2-python-libs-2.02.130-5.el7.x86_64.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/libxml2-python-2.9.1-5.el7_1.2.x86_64.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-libs-2.7.5-34.el7.x86_64.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-ipaddr-2.1.9-5.el7.noarch.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-backports-1.0-8.el7.x86_64.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-backports-ssl_match_hostname-3.4.0.2-4.el7.noarch.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-2.7.5-34.el7.x86_64.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-pycurl-7.19.0-17.el7.x86_64.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-urlgrabber-3.10-7.el7.noarch.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-setuptools-0.9.8-4.el7.noarch.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-kitchen-1.1.1-5.el7.noarch.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-chardet-2.2.1-1.el7_1.noarch.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/rpm-python-4.11.3-17.el7.x86_64.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/yum-utils-1.1.31-34.el7.noarch.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/yum-3.4.3-132.el7.centos.0.1.noarch.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/yum-plugin-aliases-1.1.31-34.el7.noarch.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/yum-plugin-protectbase-1.1.31-34.el7.noarch.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-34.el7.noarch.rpm
上这个http://vault.centos.org
网站下载对应的包。
根据你自己系统的版本,选择相对应的包。
PS: 可以用notepad++ 对上述网址进行处理,处理之后粘贴到命令行中即可。
- 执行命令,开始安装
rpm -Uvh --replacepkgs lvm2-python-libs*.rpm --nodeps --force
rpm -Uvh --replacepkgs libxml2-python*.rpm --nodeps --force
rpm -Uvh --replacepkgs python*.rpm --nodeps --force
rpm -Uvh --replacepkgs rpm-python*.rpm yum*.rpm --nodeps --force
安装成功之后,就可以测试一下yum、python是否恢复正常了。
python -V
参考文章
https://blog.csdn.net/weixin_33734785/article/details/94164300