如何将 Debian Linux 中的默认的 Python 版本切换为替代版本
来源:互联网 发布:淘宝打包能学到什么 编辑:程序博客网 时间:2024/05/27 09:45
转自:http://www.myhack58.com/Article/48/66/2016/71806.htm
当你安装 Debian Linux 时,安装过程有可能同时为你提供多个可用的 Python 版本,因此系统中会存在多个 Python 的可执行二进制文件。你可以按照以下方法使用 ls 命令来查看你的系统中都有那些 Python 的二进制文件可供使用。
$ ls /usr/bin/python*/usr/bin/python /usr/bin/python2 /usr/bin/python2.7 /usr/bin/python3 /usr/bin/python3.4 /usr/bin/python3.4m /usr/bin/python3m
执行如下命令查看默认的 Python 版本信息:
$ python --versionPython 2.7.8
1、基于用户修改 Python 版本:
想要为某个特定用户修改 Python 版本,只需要在其 home 目录下创建一个 alias(别名) 即可。打开该用户的 ~/.bashrc 文件,添加新的别名信息来修改默认使用的 Python 版本。
alias python='/usr/bin/python3.6'
一旦完成以上操作,重新登录或者重新加载 .bashrc 文件,使操作生效。
$ . ~/.bashrc
检查当前的 Python 版本。
$ python --versionPython 3.4.2
2、 在系统级修改 Python 版本
我们可以使用 update-alternatives 来为整个系统更改 Python 版本。以 root 身份登录,首先罗列出所有可用的 python 替代版本信息:
# update-alternatives --list pythonupdate-alternatives: error: no alternatives for python
如果出现以上所示的错误信息,则表示 Python 的替代版本尚未被 update-alternatives 命令识别。想解决这个问题,我们需要更新一下替代列表,将 python2.7 和 python3.4 放入其中。
# update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in auto mode# update-alternatives --install /usr/bin/python python /usr/bin/python3.4 2update-alternatives: using /usr/bin/python3.4 to provide /usr/bin/python (python) in auto mode
–install 选项使用了多个参数用于创建符号链接。最后一个参数指定了此选项的优先级,如果我们没有手动来设置替代选项,那么具有最高优先级的选项就会被选中。这个例子中,我们为 /usr/bin/python3.4 设置的优先级为2,所以 update-alternatives 命令会自动将它设置为默认 Python 版本。
# python --versionPython 3.4.2
接下来,我们再次列出可用的 Python 替代版本。
# update-alternatives --list python/usr/bin/python2.7/usr/bin/python3.4
现在开始,我们就可以使用下方的命令随时在列出的 Python 替代版本中任意切换了。
# update-alternatives --config python# python --versionPython 2.7.8
3、移除替代版本
一旦我们的系统中不再存在某个 Python 的替代版本时,我们可以将其从 update-alternatives 列表中删除掉。例如,我们可以将列表中的 python2.7 版本移除掉。
# update-alternatives --remove python /usr/bin/python2.7update-alternatives: removing manually selected alternative - switching python to auto modeupdate-alternatives: using /usr/bin/python3.4 to provide /usr/bin/python (python) in auto mode
- 如何将 Debian Linux 中的默认的 Python 版本切换为替代版本
- 将Linux下python默认版本切换成替代版本
- Debian中如何切换默认Python版本
- Debian中如何切换默认Python版本
- 如何切换python的默认版本类型
- 如何将切换anaconda 的Python 版本
- Mac OS X 上如何切换默认的 Python 版本?
- Debian中切换python版本
- Linux下对默认Python版本的切换
- 【译】Debian Linux下如何设置与更改默认python版本
- ubtunu 切换python的默认版本
- ubuntu切换默认Python版本
- MAC python默认版本切换
- 电脑装了两个版本的python,window 命令行如何切换默认python平台
- 在Linux(fedora16)中如何安装Python3.2,并设定其为默认的Python版本?
- linux下python默认版本的选择
- 将CentOS 6.7默认的Python 2.6.6升级为2.7.4版本
- perl的默认版本切换
- ionic-简单购物车
- sql语句中的left join,right join,inner join的区别
- D3D11 法线贴图(凹凸贴图)
- 实现一个函数,打印乘法口诀表,口诀表的行数和列数自己指定
- 队列详解——循环队列(顺序结构),链队列,循环队列(只有尾指针),字符队列(顺序结构)
- 如何将 Debian Linux 中的默认的 Python 版本切换为替代版本
- 克鲁斯卡尔(kruskal)法求最小生成树
- Linux系统下的用户管理及权利下放
- [贪心] 51Nod1476 括号序列的最小代价
- 一、JDK下载以及环境变量配置
- 封装类
- 搜索巨合集
- Zookeeper 本地模拟伪集群环境(一 leader 多 follower)
- 类行为型模式——模板方法(TemplateMethod)