自己開發(fā)會(huì)較為經(jīng)常使用python3, 不過很多程序依賴python2,因此需要經(jīng)常切換python版本。本方法基于ubuntu16.04,靈感來源于gcc版本切換
首先輸入命令
locate /usr/bin/python*
我的結(jié)果如下:
/usr/bin/python /usr/bin/python-config /usr/bin/python2 /usr/bin/python2-config /usr/bin/python2.7 /usr/bin/python2.7-config /usr/bin/python3 /usr/bin/python3.5 /usr/bin/python3.5m /usr/bin/python3m /usr/bin/pythontex /usr/bin/pythontex3
說明我額外安裝了python2.7 和 python3.5。下面將改變通過改變優(yōu)先級(jí)的方式來改變python版本。 輸入以下命令:
sudo update-alternatives –install /usr/bin/python python /usr/bin/python2 100 sudo update-alternatives –install /usr/bin/python python /usr/bin/python3 150 這樣再輸入 python –version 應(yīng)該顯示python3的版本號(hào)
如果想切換python的其他版本,只需要輸入:
sudo update-alternatives –config python
選擇需要的版本號(hào)即可
新聞熱點(diǎn)
疑難解答
網(wǎng)友關(guān)注