我们先使用python -v来测试一下当前版本:
ortonwu@ubuntu:~$ python -V
Python 2.7
Python 2.7
升级或安装Python3的话,可以使用如下命令下载最新的Python:
apt-get install python3
之后输入python可以进入python的命令行交互:
ortonwu@ubuntu:/usr/bin$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.>>>
Python 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.>>>
这里显示的Python版本是2.7,而不是刚下载的3.5。这是因为python被软连接到python2.7了。可以在/usr/bin下查看python link文件:
ortonwu@ubuntu:~$ ll /usr/bin/ | grep ^l | grep python
lrwxrwxrwx 1 root root 26 Apr 1 20:11 dh_pypy -> ..
lrwxrwxrwx 1 root root 26 Apr 1 20:11 dh_pypy -> ..
重新建立到python3.5的软连接即可:
ortonwu@ubuntu:/usr/bin$ sudo rm -rf python
ortonwu@ubuntu:/usr/bin$ sudo ln -s /usr/bin/python3.5 /usr/bin/python
ortonwu@ubuntu:/usr/bin$ sudo ln -s /usr/bin/python3.5 /usr/bin/python
这时使用python即可进入python3.5命令行交互界面:
ortonwu@ubuntu:/usr/bin$ python
Python 3.5.2 (default, Nov 17 2016, 17:05:23) [GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.>>>
Python 3.5.2 (default, Nov 17 2016, 17:05:23) [GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.>>>