Debian 8 中可用的最新版本已经更新为了Python3.5,鉴于本机安装的 Debian 7 自带的 Python为2.7版本,为项目方便调试,现决定追加安装 Python 3,记录方法如下。
安装 python 3.5
官网上下载 Python-3.5.1.tar.xz
1 | # tar -xJvf Python-3.5.1.tar.xz |
update-alternatives切换版本
查看 Python 版本python --version
,显示依然为2.7版本,在/usr/bin中查找python 发现有2.7,3.5 两个版本。现在通过Debian提供的工具update-alternatives 来通过链接方式方便两个版本间的切换。
首先建立python的组, 添加Python2和Python3的可选项
1 | $sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 2 # 添加Python2可选项,优先级为2 |
注意,这里的/usr/bin/python链接文件,两个可选项必须是一样的,这样这个链接文件才可以选择两个不同的可选项去链接。
查看当前配置1
2
3
4
5
6
7
8
9
10root@kali:~# sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/python2.7 2 auto mode
* 1 /usr/bin/python2.7 2 manual mode
2 /usr/bin/python3.5 1 manual mode
Press <enter> to keep the current choice[*], or type selection number:
按提示输入 2 将3.5 设为最高优先级
1 | 2 |
此时再查询 python 版本 显示为3.5 .