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-alternatives
command. 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
![debian linux change alternative python version](https://linuxconfig.org/images/change-python-alternative-version-debian-linux.png)
# 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
相关文章
- linux环境下安装python 3
- How to run python interactive in current file's directory in Visual Studio Code? Python路径问题
- Linux的linux aarch64和linux x86_64
- python 保存图片_用Python从视频中提取每一帧的图片
- Python&JS宏 实现保留样式合并表格后拆分
- Linux安装 微信开发者工具(deepin linux ubt)
- python操作txt文件中数据教程[3]-python读取文件夹中所有txt文件并将数据转为csv文件
- 【Python】自动化抢勾,python软件安装教程
- Linux集群和自动化维3.5 Python(x,y)介绍
- 《精通Python网络爬虫:核心技术、框架与项目实战》——第二篇 Part 2核心技术篇 第3章 网络爬虫实现原理与实现技术 3.1 网络爬虫实现原理详解
- python 转unicode_python中将uxxxx转换为Unicode字符串的方法
- wmic linux python
- Python爬虫技术--基础篇--多进程
- Linux自学篇——linux命令英文全称及解释
- 【Linux】linux ln文件夹的链接(转)
- 寻找两个正序数组的中位数-python
- Linux下安装OpenCV+Python支持
- Python网站导航项目-3.导航数据后端管理应用开发
- 在 Python 中完成的一些大型项目有哪些?
- python二分查找的原理
- Python 教程之如何使用 matplotlib 在 python 中绘制数学函数
- 转 windows下安装pycharm并连接Linux的python环境 以及 windows 下notepad ++编辑 linux 的文件
- 《Python硬件编程实战》——1.3 Python的特点
- Linux 如何将linux主机变为路由器&&iptables的基本用法
- Python :集合推导式和字典推导式
- Linux学习笔记(19)linux定时任务(crontab)
- Linux学习笔记(10)linux网络管理与配置之一——主机名与IP地址,DNS解析与本地hosts解析(1-4)
- Python程序设计题库——第一章
- python使用pexpect与screen进行交互控制启动ffmpeg
- Python脚本完美解决Linux环境解压.zip文件乱码问题
- 【Linux】linux下用python获取底层硬件信息接口
- 【Linux学习笔记】解决:yum install python-dev 报错(CentOS安装Python-dev库)
- 不同操作系统Windows/Linux/MacOS中python环境通过pip安装mysqlclient遇到的问题及解决方案
- Python蓝桥杯训练:基本数据结构 [二叉树] 中
- 科研初体验之Linux服务器的入门使用,关于分配了Linux账号之后怎么用,以及怎么利用Linux服务器来跑我们的python代码