How to switch between Python versions on Fedora Linux

Currently, the default python version on Fedora Linux is Python 2. Later
Fedora Linux release 22 will ship with the Python 3 as a default
version. In this config you will learn how to switch between python
versions on Fedora Linux. Let's start by listing all Python versions
available on your Fedora system:

# ls /usr/bin/python*
/usr/bin/python /usr/bin/python2.7 /usr/bin/python3 /usr/bin/python3.4m /usr/bin/python-coverage
/usr/bin/python2 /usr/bin/python2-coverage /usr/bin/python3.4 /usr/bin/python3-mako-render

Now, check your default python version:

# python -V
Python 2.7.8

To change python version on per user basis simply create a new alias in you .bashrc located under your home directory:

$ alias python='/usr/bin/python3.4'
$ . ~/.bashrc
$ python --version
Python 3.4.2

To change python version globally first check whether python alternative version is already registered by alternatives command:

# alternatives --list | grep -i python

No output means not alternative python version is configured yet. Register the two above listed python version with alternative command.

# alternatives --install /usr/bin/python python /usr/bin/python3.4 2
# alternatives --install /usr/bin/python python /usr/bin/python2.7 1

The above commands will instruct alternatives command to create relevant symbolic links to be used anytime a python command is executed. We have also given python3.4 a higher priority 2 which means, if no python alternative is selected the python3.4 will be used as default. After execution of the above commands your python version should change to python3.4 due to its higher priority.

# python -V
Python 3.4.1

To switch between above alternative python version is now simple as:

# alternatives --config python

There are 2 programs which provide 'python'.

  Selection    Command
-----------------------------------------------
*+ 1 /usr/bin/python3.4
2 /usr/bin/python2.7 Enter to keep the current selection[+], or type selection number: 2
[root@localhost fedora]# python -V
Python 2.7.8

1. Appendix

Known problems with Fedora Linux and Python 3 version: Error message:

# yum search package
File "/usr/bin/yum", line 30
except KeyboardInterrupt, e:
^
SyntaxError: invalid syntax

If you set python3 globally on your system change the yumshebang to python2:

# vi /usr/bin/yum
FROM:
#!/usr/bin/python
TO:
#!/usr/bin/python2.7

Similarly: Error message:

Downloading packages:
File "/usr/libexec/urlgrabber-ext-down", line 28
except OSError, e:
^
SyntaxError: invalid syntax
Exiting on user cancel

The issue is also related to Python 3 set as a default global version. To fix this error update /usr/libexec/urlgrabber-ext-down script:

# vi /usr/libexec/urlgrabber-ext-down
FROM:
#!/usr/bin/python
TO:
#!/usr/bin/python2.7

python更新后yum问题的更多相关文章

  1. CENTOS下Python 升级后YUM无法使用的解决办法

    Python有很多实用的工具,安装依赖python版本较高,升级Python后导致yum无法使用. 原因: 系统自带的yum依赖Python老版本,升级后不兼容 解决办法: 1. 列出所有版本,确定老 ...

  2. 如何解决python升级后yum报错

    当我们yum命令的时候,会提示 "File "/usr/bin/yum", line 30 except KeyboardInterrupt, e: ^ SyntaxEr ...

  3. 手动下载python更新后 换回以前版本

    因为用的时Ubuntu略低版本的,不想更新版本,但是经常更新内核和其他软件,尤其是最近自己更新python,但是软件更新救出错了,而且不能打开“Languae Support”(软件支持)和ibus输 ...

  4. 解决修改完系统默认python版本后yum不可用的问题!!!!!!

    文章转自: http://www.linuxidc.com/Linux/2013-05/84727.htm #vi /usr/bin/yum 将文件头部的: #!/usr/bin/python 改为: ...

  5. Python更新后ros用不了的bug

    一.原因 我同时安装了python2.7 和3.5,而且将python默认配置为python3.5,所以ros并不支持,所以提示找不到. 2.解决方式 通过修改不同版本的python的优先级,将pyt ...

  6. linux中python环境搭建及升级后yum不可用解决方案

    1.1 LinuxCentOS 为例.1.1.1 升级 Python(1) 下载 Python 版本$ wget https://www.python.org/ftp/python/2.7.11/Py ...

  7. CentOS 6.5升级Python后yum不可用的解决方案

    因开发需要,今天把CentOS 6.5自带的Python2.6.6升级到了Python2.7.3.按照如下步骤进行升级 1.查看当前系统python的版本 python -V 2.下载2.7.3版本的 ...

  8. CentOS6 系统下升级python后yum命令使用时报错

    CentOS6 系统下升级python后yum命令使用时报错,如下: [root@xxxxxxx]#yumFile"/usr/bin/yum",line30exceptKeyboa ...

  9. CentOS7 升级python同时解决yum损坏问题

    CentOS7中的python版本为python2.7.5,升级到最新版的python时需要注意两个问题 新版的python安装好后要修改python的系统默认指向问题 升级到最新版python后yu ...

随机推荐

  1. 使用 Async 和 Await 的异步编程(C# 和 Visual Basic)[msdn.microsoft.com]

    看到Microsoft官方一篇关于异步编程的文章,感觉挺好,不敢独享,分享给大家. 原文地址:https://msdn.microsoft.com/zh-cn/library/hh191443.asp ...

  2. HADOOP安装指南-Ubuntu15.10和hadoop2.7.2

    Ubuntu15.10中安装hadoop2.7.2安装手册 太初 目录 1.      Hadoop单点模式... 2 1.1        安装步骤... 2 0.环境和版本... 2 1.在ubu ...

  3. 我对uml类图关系的理解

    uml类图的关系: 泛化关系也就是继承. 实现关系就是一个类实现另外一个接口. 依赖关系就是一个类使用了另外一个类,是一种使用关系,在这个类的某个服务中需要另外一个类来协助. 关联关系就是一类拥有另外 ...

  4. C语言递归,非递归实现翻转链表

    翻转链表作为,链表的常用操作,也是面试常遇到的. 分析非递归分析: 非递归用的小技巧比较多,很容易出错. 递归分析比较简单,在代码里面 代码: #include<stdio.h> #inc ...

  5. 化繁为简——分解复杂的SQL语句

    今天同事咨询一个SQL语句,如下所示,SQL语句本身并不复杂,但是执行效率非常糟糕,糟糕到一塌糊涂(执行计划也是相当复杂).如果查询条件中没有NOT EXISTS部分,倒是不要一秒就能查询出来. SE ...

  6. Linux启动报错missing operating system

    用UltraISO制作了一个Red Hat Enterprise Linux Server release 5.7系统的U盘启动盘,然后在一台PC上安装,由于安装过程中在干别的事情,有些选项没有细看. ...

  7. js字符串转为日期格式

    1. <script type="text/javascript"> //字符串转日期格式,strDate要转为日期格式的字符串 function getDate(st ...

  8. Redis学习笔记4-Redis配置详解

    在Redis中直接启动redis-server服务时, 采用的是默认的配置文件.采用redis-server   xxx.conf 这样的方式可以按照指定的配置文件来运行Redis服务.按照本Redi ...

  9. extjs学习资料

    ExtJs 入门教程 1.Extjs5.1.0教程云盘地址 http://pan.baidu.com/s/1qYhHiEw 2.Extjs3.x如下:   ExtJs 入门教程一[学习方法] ExtJ ...

  10. java设计模式之原型模式

    原型模式概念 该模式的思想就是将一个对象作为原型,对其进行复制.克隆,产生一个和原对象类似的新对象.java中复制通过clone()实现的.clone中涉及深.浅复制.深.浅复制的概念如下: ⑴浅复制 ...