python更新后yum问题

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
[[email protected] 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
时间: 2025-01-05 14:21:10

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

python更新导致yum无法使用

问题: There was a problem importing one of the Python modulesrequired to run yum. The error leading to this problem was:   No module named yumPlease install a package which provides this module, orverify that the module is installed correctly.It's poss

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

因为用的时Ubuntu略低版本的,不想更新版本,但是经常更新内核和其他软件,尤其是最近自己更新python,但是软件更新救出错了,而且不能打开“Languae Support”(软件支持)和ibus输入法,非常烦恼,尝试了很多解决方法,但是都不行,只能再改回来了. 改回步骤如下: 改回以前的python,其实就是修改链接. 1. 删除链接,即: rm /usr/bin/python 2. 重建链接,连接到系统python. 首先,查看自己python版本号: ls /usr/bin | grep

升级Python版本后 yum命令不可用

新版本python安装目录 /usr/local/python3 # ./configure --prefix=/usr/local/python3 # make && make install # mv /usr/bin/python /usr/bin/python_old #把旧版本的python移至python_old下 # ln -s /usr/local/python3/bin/python /usr/bin/python #创建新版本链接 # yum -y install gc

如何解决python升级后yum报错

当我们yum命令的时候,会提示 "File "/usr/bin/yum", line 30 except KeyboardInterrupt, e: ^ SyntaxError: invalid syntax" 可能是升级python引起的,yum是用python作为解释器的. 1.当我们输入任何yum命令,都会报错.原因是升级python后,导致yum所需版本不一致导致! 2.如图,我将python版本编译安装python3.3.0.将3.3链接到/usr/bin

python升级后yum不能使用报错 File “/usr/bin/yum”, line 30

python 2.7升级python3.4之后yum库不能使用.报错: [[email protected] 桌面]# yum upgrade  File "/usr/bin/yum", line 30    except KeyboardInterrupt, e:  [[email protected] 桌面]# vim /usr/bin/yum    #将!/usr/bin/python改成!/usr/bin/python2.7即可. 原来是由于升级了默认的python导致的后果.

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

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

Python更新后ros用不了的bug

一.原因 我同时安装了python2.7 和3.5,而且将python默认配置为python3.5,所以ros并不支持,所以提示找不到. 2.解决方式 通过修改不同版本的python的优先级,将python2.7设置为最高,即设置为默认python. sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 200 sudo update-alternatives --install /usr/bin/p

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

因开发需要,今天把CentOS 6.5自带的Python2.6.6升级到了Python2.7.3.按照如下步骤进行升级 1.查看当前系统python的版本 python -V 2.下载2.7.3版本的Python wget http://python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2 3.解压和安装 tar -jxvf Python-2.7.3.tar.bz2 #进入解压后的目录 cd Python-2.7.3 #编译和安装 ./configur

Python升级版本及版本升级后Yum无法使用的解决方法

#升级版本 yum -y install gcc cd /opt wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tgz tar xf Python-2.7.6.tgz  ./configure --prefix=/usr/local/python2.7  cd Python-2.7.6 ./configure --prefix=/usr/local/python2.7  make && make install mv /usr/b