自己開發會較為經常使用python3, 不過很多程序依賴python2,因此需要經常切換python版本。本方法基于ubuntu16.04,靈感來源于gcc版本切換
首先輸入命令
locate /usr/bin/python*
我的結果如下:
/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。下面將改變通過改變優先級的方式來改變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 應該顯示python3的版本號
如果想切換python的其他版本,只需要輸入:
sudo update-alternatives –config python
選擇需要的版本號即可
新聞熱點
疑難解答