sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.6
好吧,仅仅做这一步,根本就不够,还要安装pip和python3.6-dev:
#安装pip
wget https://bootstrap.pypa.io/get-pip.py --no-check-certificate
python3 get-pip.py
#安装python3.6-dev
apt-get install python3.6-dev
————————————————
将Python版本从2.7切换到3.6
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.4 2
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 3
#update-alternatives是ubuntu系统中专门维护系统命令链接符的工具,通过它可以很方便的设置系统默认使用哪个命令、哪个软件版本
上面三行指令最后的数字 1 2 3 分别代表优先级。1是最高。所以等下 config的时候,会发现默认版本是2.7(因为它的优先级设为了1).
1
2
3
4
5
6
而后输入sudo update-alternatives --config python(这是一个切换Python版本的指令),会出现如下选项:
dale@deheng:~$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 3 dale@deheng:~$ sudo update-alternatives
–config python There are 4 choices for the alternative python (providing /usr/bin/python).>
Selection Path Priority Status
0 /usr/bin/python3.6 3 auto mode
1 /usr/bin/python2.7 1 manual mode
2 /usr/bin/python3.4 2 manual mode
3 /usr/bin/python3.6 3 manual mode
4 /usr/local/lib/python2.7 1 manual mode
Press enter to keep the current choice[*], or type selection number: 3
update-alternatives: using /usr/bin/python3.6 to provide
/usr/bin/python (python) in manual mode
如上,通过输入Python3.6对应的数字3,成功将Python版本设置成3.6。在此查看如下:
dale@deheng:~$ python
–version Python 3.6.3