Ubuntu默認安裝了Python2.7和3.5
輸入命令python
image.png
按Ctrl+D退出python命令行
image
輸入命令sudo add-apt-repository ppa:jonathonf/python-3.6
image.png
如果報錯: add-apt-repository: command not found
解決辦法:
sudo apt-get install software-properties-common python-software-properties
完成這個,就可以使用add-apt-repository命令了。
按Enter確認
輸入命令sudo apt-get update
輸入命令sudo apt-get install python3.6
按Y確認
調整Python3的優先級,使得3.6優先級較高
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2
更改默認值,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
此時再輸入命令python
image
可以看到此時已經是Python3.6了