How to change from default to alternative Python version on Debian Linux
https://linuxconfig.org/how-to-change-from-default-to-alternative-python-version-on-debian-linux
Your Debian Linux installation may include multiple python versions and thus also include multiple python binary executables. You can run the following ls command to find out what python binary executables are available on your system:
$ 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
To check what is your default python version execute:
$ python --version
Python 2.7.8
Change python version on per user basis
To change a python version on per user basis you simply create an alias within user's home directory. Open ~/.bashrc file and add new alias to change your default python executable:
alias python='/usr/bin/python3.4'
Once you make the above change, re-login or source your .bashrc file:
$ . ~/.bashrc
Check your default python version:
$ python --version
Python 3.4.2
Change python version system-wide
To change python version system-wide we can use update-alternatives command. Logged in as a root user, first list all available python alternatives:
# update-alternatives --list python
update-alternatives: error: no alternatives for python
The above error message means that no python alternatives has been recognized by update-alternativescommand. For this reason we need to update our alternatives table and include both python2.7 and python3.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
The --install option take multiple arguments from which it will be able to create a symbolic link. The last argument specified it priority means, if no manual alternative selection is made the alternative with the highest priority number will be set. In our case we have set a priority 2 for /usr/bin/python3.4 and as a result the /usr/bin/python3.4 was set as default python version automatically by update-alternatives command.
# python --version
Python 3.4.2
Next, we can again list all python alternatives:
# update-alternatives --list python
/usr/bin/python2.7
/usr/bin/python3.4
From now on, we can anytime switch between the above listed python alternative versions using below command and entering a selection number:
# update-alternatives --config python

# python --version
Python 2.7.8
Appendix
In case we no longer have the alternative python version installed on our system we can remove its update-alternatives listing. For example let's remove python2.7 version:
# 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
How to change from default to alternative Python version on Debian Linux的更多相关文章
- Change the default MySQL data directory with SELinux enabled
转载:https://rmohan.com/?p=4605 Change the default MySQL data directory with SELinux enabled This is a ...
- 【LeetCode】518. Coin Change 2 解题报告(Python)
[LeetCode]518. Coin Change 2 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目 ...
- MATLAB/SIMULINK生成代码错误之change the default character encoding setting
SIMULINK点击生成C代码报错 错误提示: Error encountered while executing PostCodeGenCommand for model 'RTW_sc3': Cl ...
- 尚学python课程---11、linux环境下安装python注意
尚学python课程---11.linux环境下安装python注意 一.总结 一句话总结: 准备安装依赖包:zlib.openssl:yum install zlib* openssl*:pytho ...
- 安装 pywin32-218.win32-py2.7.exe 报错python version 2.7 required,which was not found in the registry解决方案
随便在一个盘下 新建register.py的文件,内容如下: # # script to register Python 2.0 or later for use with win32all ...
- 【转】安装第三方库出现 Python version 2.7 required, which was not found in the registry
安装第三方库出现 Python version 2.7 required, which was not found in the registry 建立一个文件 register.py 内容如下. 然 ...
- Python 安装Twisted 提示python version 2.7 required,which was not found in the registry
由于我安装Python64位的,下载后没注册,安装Twisted时老提示“python version 2.7 required,which was not found in the registry ...
- How to Access MySQL with Python Version 3.4
http://askubuntu.com/questions/630728/how-to-access-mysql-with-python-version-3-4 How to Access MySQ ...
- 安装第三方库出现 Python version 2.7 required, which was not found in the registry
安装第三方库出现 Python version 2.7 required, which was not found in the registry 建立一个文件 register.py 内容如下. 然 ...
随机推荐
- JSP +MySQL实现网站的登录与注册小案例
为了练手,我就自己试着做了一个网站的登录与注册的小案例.由于没有做美化处理,所以界面并不是很好看. 网站实现的功能如下: 用户首次注册功能 用户登录功能 项目目录展示: 下面我将会分模块展示 注册模块 ...
- flume1.4.0 保存文件到hdfs错误调试
报错如下 解决方案:将FLUME_HOME/lib目录下的jar文件,替换成HADOOP_HOME/share/hadoop/common/lib下版本更新的jar文件
- Html标签中thead、tbody、tfoot的作用
Html标签中thead.tbody.tfoot的作用 为了让大表格(table)在下载的时候可以分段的显示,就是说在浏览器解析HTML时,table是作为一个整体解释的,使用TBODY可以优化显示. ...
- IE浏览器打印的页眉页脚设置解决方法
首先说明问题: 默认情况下,通过IE的打印对话框,打印出来的内容都有页眉和页脚的. 查看ie的页面设置发现如右图中,页眉页脚 下面先说明&w&bPage&p of &P ...
- Framework启动过程浅析
浅显的总结一下Framework启动大概过程 总体 Android底层是linux系统,因而在开机时仍然是运行天字第一号进程inti,读取init.rc来创建第一个Dalvik进程zygote,下面是 ...
- Android用AlarmManager实现后台任务-android学习之旅(63)
因为Timer不能唤醒cpu,所以会在省电的原因下失效,所以需要唤醒cpu在后台稳定化的执行任务,AlarmManager能够唤醒cpu 这个例子讲解了如何通过Service来在后他每一个小时执行.特 ...
- Android图片色彩变幻
最近在做图片相关的应用,所以就各方积累到一些常用的操作,一般来说会有多种方式来实现这一功能,比如 采用色度变换 采用ColorMatrix颜色矩阵 采用对像素点的直接操作 等等,今天就复习一下第一种方 ...
- 自建log4cxx.sln
log4cxx的下载包是0.10版本的,代码较旧,有些错误,应该从主干下载最新的代码. 0.10的下载包中有projects目录,内有VC6的工程文件; 还有site目录,内有vc构建的帮助文档vst ...
- 结构体:探析C#文件方式读写结构体
最近直在研究Net Micro Framework字体文件(tinyfnt)由于tinyfnt文件头部有段描述数据所以很想 定义个结构体像VC样直接从文件中读出来省得用流个个解析很是麻烦 没有想到在中 ...
- linux shell (()) 双括号运算符使用
估计很多朋友都感觉比较难以接受.特变逻辑运算符"[]"使用时候,必须保证运算符与算数 之间有空格. 四则运算也只能借助:let,expr等命令完成. 今天讲的双括号"(( ...