先查看當前python版本:
python --version
我的是linux自帶的2.7.5
查看wget權限:
ls -l /usr/bin/wget
我這里是有權限的,如果沒有需要給wget授權:
chmod 755 /usr/bin/wget
wget下載python:
wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz
將下載好的tgz進行解壓:
tar -zxvf Python-3.7.4.tgz
進入解壓后的目錄:
cd Python-3.7.7/
./configure
沒有升級過Python就需要安裝Python相關的依賴包:
yum update -y
yum install -y make gcc gcc-c++
yum -y install zlib*
yum -y install libffi-devel
./configure
編譯:
make
安裝
make install
查看python版本:
python --version
查看python的路徑,在/usr/bin下面,可以看到python的鏈接是python2.7,所以執行python就相當於是執行python2.7。
設置3.7.4為默認版本:
ls -la /usr/bin | grep python
將原來的python的軟連接重命名:
mv /usr/bin/python /usr/bin/python.bak
創建軟連接:
ln -s /home/anne/Python-3.7.4/python /usr/bin/python
再次查看python版本,顯示已經是3.7.4