ubuntu下Python升级到3.6.7

2019-02-21  本文已影响0人  tafanfly

观察python版本

当前环境有python 2.7.12版本,并且软链接到了python,有python 3.5.2版本,并且软链接到了python 3,也可以用命令ls -al /usr/bin | grep python查看。

$ python -V
Python 2.7.12
$ python2 -V
Python 2.7.12
$ python3 -V
Python 3.5.2
$ python3.5 -V
Python 3.5.2

ubuntu下Python升级到3.6.7

因为项目需求,需要Python版本升级到3.6,与其他的python并存。
按照下列命令顺序安装,即可成功安装python3.6

sudo add-apt-repository ppa:jonathonf/python-3.6
sudo apt update
sudo apt install python3.6

注意:如果出现了超时的话:
(1)请在.bashrc文件里面设置好代理。
(2)如果还是出错,直接进入root权限下安装, 记得去掉上面命令中的sudo

GtkWarning: could not open displayCannot add PPA: '"Error reading https://launchpad.net/api/1.0/~jonathonf/+archive/python-3.6: (7, 'Failed to connect to launchpad.net port 443: Connection timed out')"'

设置python软链接

lrwxrwxrwx  1 root root             9 Nov 24  2017 python -> python2.7
lrwxrwxrwx  1 root root             9 Nov 24  2017 python2 -> python2.7

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 2

切换python3的指向版本, 命令sudo update-alternatives --config python3

$ sudo update-alternatives --config python3
There are 2 choices for the alternative python3 (providing /usr/bin/python3).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3.5   2         auto mode
  1            /usr/bin/python3.5   2         manual mode
  2            /usr/bin/python3.6   1         manual mode

Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/bin/python3.6 to provide /usr/bin/python3 (python3) in manual mode

$ python3 -V
Python 3.6.7
上一篇下一篇

猜你喜欢

热点阅读