当你安装 Debian Linux 时,安装过程有可能同时为你提供多个可用的 Python 版本,因此系统中会存在多个 Python 的可执行二进制文件。一般Ubuntu默认的Python版本都为2.x, 如何改变Python的默认版本呢?下面来一起看看吧。
 

你可以按照以下方法使用 ls 命令来查看你的系统中都有那些 Python 的二进制文件可供使用。

1
2
$ 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 版本信息:

1
2
$ python --version
Python 2.7.8

1、基于用户修改 Python 版本:

想要为某个特定用户修改 Python 版本,只需要在其 home 目录下创建一个 alias(别名) 即可。打开该用户的 ~/.bashrc文件,添加新的别名信息来修改默认使用的 Python 版本。

1
alias python='/usr/bin/python3.4'

一旦完成以上操作,重新登录或者重新加载 .bashrc 文件,使操作生效。

1
$ . ~/.bashrc

检查当前的 Python 版本。

1
2
$ python --version
Python 3.4.2

2、 在系统级修改 Python 版本【/etc/alternatives/】

我们可以使用 update-alternatives 来为整个系统更改 Python 版本。以 root 身份登录,首先罗列出所有可用的 python 替代版本信息:

1
2
# update-alternatives --list python
update-alternatives: error: no alternatives for python

如果出现以上所示的错误信息,则表示 Python 的替代版本尚未被 update-alternatives 命令识别。想解决这个问题,我们需要更新一下替代列表,将 python2.7 和 python3.4 放入其中。

1
2
3
4
# update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-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 2
update-alternatives: using /usr/bin/python3.4 to provide /usr/bin/python (python) in auto mode

--install 选项使用了多个参数用于创建符号链接。最后一个参数指定了此选项的优先级,如果我们没有手动来设置替代选项,那么具有最高优先级的选项就会被选中。这个例子中,我们为 /usr/bin/python3.4 设置的优先级为2,所以update-alternatives 命令会自动将它设置为默认 Python 版本。

1
2
# python --version
Python 3.4.2

接下来,我们再次列出可用的 Python 替代版本。

1
2
3
# update-alternatives --list python
/usr/bin/python2.7
/usr/bin/python3.4

现在开始,我们就可以使用下方的命令随时在列出的 Python 替代版本中任意切换了。

1
# update-alternatives --config python

1
2
# python --version
Python 2.7.8

3、移除替代版本

一旦我们的系统中不再存在某个 Python 的替代版本时,我们可以将其从 update-alternatives 列表中删除掉。例如,我们可以将列表中的 python2.7 版本移除掉。

1
2
3
4
# update-alternatives --remove python /usr/bin/python2.7
 
update-alternatives: removing manually selected alternative - switching python to auto mode
update-alternatives: using /usr/bin/python3.4 to provide /usr/bin/python (python) in auto mode

方法2、移除软连接

1
2
3
rm -rf /data/logs
 
ln -s /temp/logs /data/logs

解决软连接ln报错-bash: /usr/local/bin/mysql: Too many levels of symbolic links

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流。

更改Ubuntu默认python版本的两种方法python-> Anaconda的更多相关文章

  1. Git恢复之前版本的两种方法reset、revert

    实战 回退 1.删除之前的提交 git reset --hard id 推送到远程 git push -f [git log中确实删除了,但是拿到可以恢复] 2.不删除之前的提交 git revert ...

  2. 实现LRU的两种方法---python实现

    这也是豆瓣2016年的一道笔试题... 参考:http://www.3lian.com/edu/2015/06-25/224322.html LRU(least recently used)就不做过多 ...

  3. ubuntu查看mysql版本的几种方法

    ubuntu查看mysql版本的几种方法 mysql 1:在终端下:mysql -V(大写) //代码 $ mysql -V mysql Ver 14.14 Distrib 5.5.46, for d ...

  4. ubuntu 安装JAVA jdk的两种方法:

    ubuntu 安装jdk 的两种方式: 1:通过ppa(源) 方式安装. 2:通过官网下载安装包安装. 这里推荐第1种,因为可以通过 apt-get upgrade 方式方便获得jdk的升级 使用pp ...

  5. Git恢复之前版本的两种方法reset、revert(图文详解)

    一.问题描述在利用github实现多人合作程序开发的过程中,我们有时会出现错误提交的情况,此时我们希望能撤销提交操作,让程序回到提交前的样子,本文总结了两种解决方法:回退(reset).反做(reve ...

  6. Git恢复之前版本的两种方法reset、revert(图文详解)(转)

    一.问题描述在利用github实现多人合作程序开发的过程中,我们有时会出现错误提交的情况,此时我们希望能撤销提交操作,让程序回到提交前的样子,本文总结了两种解决方法:回退(reset).反做(reve ...

  7. python 开启进程两种方法 multiprocessing模块 介绍

    一 multiprocessing模块介绍 python中的多线程无法利用多核优势,如果想要充分地使用多核CPU的资源(os.cpu\_count\(\)查看),在python中大部分情况需要使用多进 ...

  8. Windows下创建Python虚拟环境的两种方法:

    在实际的项目开发中,我们会根据自己的需求去下载各种相应的框架库,但是每个项目可能使用的库不一样,或者版本不一样等等等.为了避免这些因素对我们的项目造成一些不必要的影响,我们可能需要来回的切换或者装卸等 ...

  9. 安装python包的两种方法

    1.在 anaconda 环境中安装包 selenium conda install selenium 2.python 下安装包 selenium pip install selenium 3.测试 ...

随机推荐

  1. 把leveldb嵌入到redis.实现真正的数据持久存储

    目前最新版RedisStorage 是基于 redis 2.6.2基础上,加上 leveldb存储引擎. 这个项目是源于 公司项目的passport 用户认证改造.公司一个项目运行了N年.积累了几千万 ...

  2. Android Studio无法打印Logout日志

    华为手机: 在拨号界面输入:*#*#2846579#*#* 进入测试菜单界面,然后Project Menu → 后台设置 → LOG设置LOG 开关 → LOG 打开        LOG 级别设置 ...

  3. JQuery UI之Autocomplete(1)入门程序

    1.Autocomplete的主要属性:source:即为指定智能提示下拉框中的数据来源,支持三种类型.  Array,主要用于本地化数据提供,支持两种格式:字符串数组 [ "Choice1 ...

  4. initialize flexnet service failed error code 50003

    网络上下载回来的绿色版Xshell/Xftp在每次启动时都会报这个错,通过FlexNet Licensing Service 安装与卸载脚本了解到,程序 启动的时候会检查FlexNet Licensi ...

  5. python 数据类型 之 字典

    python 3.6.5字典的特性和定义定义:{'key_1':vlaue_1,'key_2':value_2}1.键与值用冒号 : 分开2.项与项 用 , 分开 特性1.可以存放多个值,可以不唯一, ...

  6. opencv 3.2图像矩(Image Moments)

    图像矩乍看比较难理解,看了很多资料,大概明白了一些,但还是无法在脑海里形成一个模型概念,于是从源码中寻找它的应用. 今天就通过公式和程序抓取数据,来进一步理解图像矩 先看一个图片 这是程序运行结果, ...

  7. 第一个android ijkplayer播放器

    创建一个ijkplayer的播放器项目,需要三步设置: 一.在activity_main.xml中添加播放器标签 <com.smallart.myapplication.media.IjkVid ...

  8. git-flow 备忘清单

    原文地址:http://danielkummer.github.io/git-flow-cheatsheet/index.zh_CN.html

  9. JoyOI1935 导弹防御塔

    原题链接 首先可以二分答案,然后考虑检验答案. 我们可以对炮塔进行拆点,即能发射\(x\)颗导弹就拆成\(n\times x\)个点,作为一个集合,另一个集合则是\(m\)个侵入者,然后对于能在剩余时 ...

  10. 在nodejs里面是用类似配置文件的方法

    1.a.js exports.MYSQLIP = '127.0.0.1'; exports.MYSQLPORT = 1336; 2.b.js const C = require('./config/c ...