1. 程式人生 > >CentOS誤刪 ython2.7,不能使用yum,重新安裝python

CentOS誤刪 ython2.7,不能使用yum,重新安裝python

開發十年,就只剩下這套架構體系了! >>>   

借鑑部落格:

https://blog.csdn.net/qq_36653942/article/details/80712088

場景:

    誤刪usr/lib/python包,不能使用yum。

    主機版本:7.4.1708

建立目錄python和yum用以存放rpm包:

備註:到http://vault.centos.org/7.4.1708/os/x86_64/Packages下找到對應版本

7.4.1708:為centos版本號,

使用指令檢視主機對應版本號:cat /etc/redhat-release

 

#mkdir /usr/local/python
cd /usr/local/python 
wget http://vault.centos.org/7.4.1708/os/x86_64/Packages/python-2.7.5-58.el7.x86_64.rpm
wget http://vault.centos.org/7.4.1708/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
wget http://vault.centos.org/7.4.1708/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm
wget http://vault.centos.org/7.4.1708/os/x86_64/Packages/python-devel-2.7.5-58.el7.x86_64.rpm
wget http://vault.centos.org/7.4.1708/os/x86_64/Packages/python-libs-2.7.5-58.el7.x86_64.rpm
wget http://vault.centos.org/7.4.1708/os/x86_64/Packages/python-urlgrabber-3.10-8.el7.noarch.rpm
wget http://vault.centos.org/7.4.1708/os/x86_64/Packages/rpm-python-4.11.3-25.el7.x86_64.rpm

#強制執行安裝
rpm -ivh python-*   rpm-python-*
如果:
出現安裝包的依賴問題,此時如下解決即可:
pm -ivh python-*   rpm-python-* --nodeps --force
#--nodeps --force為不考慮依賴包,強制安裝。
#使用python指令 ,驗證安裝結果。

#mkdir /usr/local/yum
cd /usr/local/yum
wget http://vault.centos.org/7.4.1708/os/x86_64/Packages/yum-3.4.3-154.el7.centos.noarch.rpm
wget http://vault.centos.org/7.4.1708/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://vault.centos.org/7.4.1708/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-42.el7.noarch.rpm

#rpm -ivh yum-* 

#yum指令測試

##python3.6安裝教程

1.首先下載需要安裝的python版本:本次使用python-3.6.3

2.mkdir /usr/local/python3

3.解壓python-3.6.3.tar至python3資料夾
tar -zxvf python-3.6.3.tar -C /usr/local/python3
4.安裝依賴--tkinter,bz2庫
python需要tkinter
yum -y install tkinter tcl-devel tk-devel
python需要bz2庫
yum install bzip2-devel

5.進入解壓後的python原始檔,使用make指令
./configure --prefix=/usr/local/python3  #指定安裝目錄
make
make install

6.最後建立軟連線
n -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

7.測試安裝結果
>>python3
>>pip3