最近在Ubuntu16.04安装了python3.5还有系统自带的python2.7.13,总结一下不同版本的切换问题。

  • alias:别名
  • bashrc:个人配置文件

一、修改Python版本(针对用户)

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

alias python='/usr/bin/python3.5'

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

 . ~/.bashrc

  检查当前的 Python 版本。

python --version

  

二、修改python版本(针对整个系统)

可以用update-alternatives指令实现整个系统级修改Python版本。前提是以root用户的身份登陆。

  • 进入root用户:

    sudo -
    

     会提示输入Password:输入密码即可登陆。

  • 如果是第一次使用root身份,ubuntu系统默认是没有激活root用户的,需要手动激活,终端下输入:
sudo passwd root

  会提示:Enter new UNIX password:,按要求输入密码,这样就完成了激活,再次sudo -,登陆完成。

  • su

    • su //切换到超级用户
    • su username//切换到username用户
    • su与sudo su区别:参考这里

登陆root用户后,查看python所有版本:

update-alternatives

  如果出现报错信息:

update-alternatives: error: no alternatives for python

  这说明python alternatives没有没update-alternatives识别,我们需要更新alternatives table使其包括python 2.7和python3.5.

update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in auto mode
update-alternatives: using /usr/bin/python3.5 to provide /usr/bin/python (python) in auto mode

  这个时候电脑提示:syntax error near unexpected token '(',这是没有识别(,需要进行转义:

update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python \(python\) in auto mode
update-alternatives: using /usr/bin/python3.5 to provide /usr/bin/python \(python\) in auto mode

  又提示出了错误:

No command 'update-alternatives:' found, did you mean:

Command 'update-alternatives' from package 'dpkg' (main)

update-alternatives:: command not found

暂时未解决。

参考:

Ubuntu下python两个版本的切换的更多相关文章

  1. Ubuntu下多个gcc版本之间的切换

    Ubuntu下多个gcc版本之间的切换 1.查看当前系统的gcc版本 gcc -v 会输出以下信息: Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO ...

  2. ubuntu下python 2.7与python 3.X的转换

    ubuntu下python 2.7与python 3.X的转换 由于ubuntu本身自带python 2.7,而python 3.X与2.7有很多不同,所以在使用python 3.X时会带来诸多不便. ...

  3. ubuntu 下python安装及hello world

    //@desn:ubuntu 下python安装及hello world //@desn:码字不宜,转载请注明出处 //@author:张慧源  <turing_zhy@163.com> ...

  4. ubuntu下python flask环境搭建

    ubuntu下python flask环境搭建 1. 安装pip sudo apt-get install python-dev pyhton-pip 2. 安装virtualenv sudo apt ...

  5. ubuntu 下python版本切换

    1. 安装ubuuntu 14.04之后python的默认版本为2.7.6但是我想使用python的版本为3.4 可以打开终端:输入:alias python = python3

  6. ubuntu 下python环境的切换使用

    如何在Anaconda的python和系统自带的python之间切换 一般ubuntu下有三种python环境,1. 系统自带python2,3;在/usr/bin路径下:2. anaconda下安装 ...

  7. Ubuntu 下 Python自由切换

    sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100 sudo update-alternati ...

  8. ubuntu下Python的安装和使用

    版权声明 更新:2017-04-13-上午博主:LuckyAlan联系:liuwenvip163@163.com声明:吃水不忘挖井人,转载请注明出处! 1 文章介绍 本文介绍了Python的开发环境. ...

  9. Ubuntu下python开发环境搭建

    配置语言 1) 依次点击设置--Region & Language--Manage Installed Languages --install/remove language--chinese ...

随机推荐

  1. MFC apps must not include windows.h

    用VS2008建立一个DLL项目,一开始的时候不想用MFC, 所以选择的是使用标准Windows库. 使用了一段时间后又想用MFC了,所以把选项改成使用在共享 DLL 中使用 MFC. 但是编译的时候 ...

  2. Pinger

    import java.io.IOException;import java.io.InputStreamReader;import java.io.LineNumberReader;import j ...

  3. Android 之开发积累

    1.后台设置ImageView的src属性 有三种方式:img = (ImageView)this.findViewById(R.id.img_result_analyze); [1]setImage ...

  4. 自我分析-Spring IOC

    Spring IOC容器实现原理大致是容器(Map)+反射(Java反射和cglib).Spring提供丰富的ApplicationContext.以FileSystemXmlApplicationC ...

  5. pcapng文件的python解析实例以及抓包补遗

    为了弥补pcap文件的缺陷,让抓包文件可以容纳更多的信息,pcapng格式应运而生.关于它的介绍详见<PCAP Next Generation Dump File Format> 当前的w ...

  6. HTML解析模块

    import html html.escape(s, quote=True) 对特殊字符进行转义 Convert the characters &, < and > in stri ...

  7. maven 如何给web项目添加jar包依赖

      maven 如何给web项目添加jar包依赖 CreateTime--2018年4月19日19:06:21 Author:Marydon 开发工具:eclipse 1.打开pom.xml文件--& ...

  8. 〖Linux〗build ssh for Arm

    1. 交叉编译环境: export ARCH=arm export SUBARCH=arm export PATH=/opt/FriendlyARM/toolschain//bin:$PATH exp ...

  9. 基于CUDA的粒子系统的实现

    基于CUDA的粒子系统的实现 用途: 这篇文章作为代码实现的先导手册,以全局的方式概览一下粒子系统的实现大纲. 科普: 对粒子进行模拟有两种基本方法: Eulerian(grid-based) met ...

  10. 原创:微信小程序+WEB使用JS实现注册【60s】倒计时功能

    1.效果图: 2.页面仅仅利用了JS的相关功能,包含:wxml.js.wxss 2.1wxml页面代码: <text>绑定手机</text> <form bindsubm ...