Linux(ubuntu18.04)切換python版本
阿新 • • 發佈:2018-12-12
前言
Ubuntu18.04系統在安裝python時會安裝兩個版本:2.7和3.6.預設情況下系統環境使用的是python2,但是我們有時需要使用python3來作為我們的開發環境,所以需要自由切換python版本.
python2切換成python3
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150
執行上面兩句命令即可將2.7版本切換成python3.6版本,想要檢視是否切換成功:
[email protected]:~$ python --version
Python 3.6.5
[email protected]:~$
python3切換成python2
[email protected]:~$ sudo update-alternatives --config python
[sudo] shanlei 的密碼:
有 2 個候選項可用於替換 python (提供 /usr/bin/python)。
選擇 路徑 優先順序 狀態
------------------------------------------------------------
* 0 /usr/bin/python3 150 自動模式
1 /usr/bin/python2 100 手動模式
2 /usr/bin/python3 150 手動模式
要維持當前值[*]請按<回車鍵>,或者鍵入選擇的編號:1
update-alternatives: 使用 /usr/bin/python2 來在手動模式中提供 /usr/bin/python (python)
[email protected]:~$ python --version
Python 2.7.15rc1
[email protected]:~$
之後我們在切換python版本時就可以使用這個命令鍵入選擇進行切換了:
sudo update-alternatives --config python