Centos7升級python
阿新 • • 發佈:2020-12-28
技術標籤:『 系統-操作系列』
1.目標
將伺服器自帶的python版本為2.7,需要升級到python3
2.安裝依賴包
yum install zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel -y
3.安裝
(1)下載
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
(2)解壓原始碼包
tar -zxvf Python-3.7.0.tgz
(3)建立安裝目錄
mkdir /usr/local/python3
(4)安裝到指定目錄
./configure --prefix=/usr/local/python3
(5)編譯
make && make install
4.設定軟連結全域性使用python3
rm -rf /usr/bin/python
rm -rf /usr/bin/python2
cd /usr/local/python3
ln -s /usr/local/python3/bin/python3 /usr/bin/python
ln -s /usr/local/bin/pip3 /usr/bin/pip
ls -l /usr/bin/python*
5.驗證
python -V
6.修改yum
vi /usr/bin/yum
將 #!/usr/bin/python 改為 #!/usr/bin/python2.7,儲存退出
vi /usr/libexec/urlgrabber-ext-down
將 #!/usr/bin/python 改為 #!/usr/bin/python2.7,儲存退出