ImportError: cannot import name to_unicode

Are you getting below error while updating working on yum

root@vps [/]# yum clean packages
Traceback (most recent call last):
File “/usr/bin/yum”, line 28, in ?
import yummain
File “/usr/share/yum-cli/yummain.py”, line 32, in ?
from yum.i18n import to_unicode, utf8_width
ImportError: cannot import name to_unicode

Below are the steps to fix this issue

Download yum rpm first

root@vps [/]# wget ftp://ftp.muug.mb.ca/mirror/centos/5.10/os/i386/CentOS/yum-3.2.22-40.el5.centos.noarch.rpm

Remove the old yum rpm from server using below command

root@vps [/]# rpm -e yum –nodeps
warning: /etc/yum.conf saved as /etc/yum.conf.rpmsave

Now installed the downloaded rpm
root@vps [/]# rpm -ivh yum-3.2.22-40.el5.centos.noarch.rpm
Preparing…                ########################################### [100%]
1:yum                    ########################################### [100%]

 

Now yum should work like charm
root@vps [/]# yum update
Loaded plugins: fastestmirror
Determining fastest mirrors
* addons: httpupdate.cpanel.net
* base: httpupdate.cpanel.net
* extras: httpupdate.cpanel.net
* update: httpupdate.cpanel.net
addons                                                                                                                                 | 1.9 kB     00:00
base                                                                                                                                   | 1.1 kB     00:00
extras                                                                                                                                 | 2.1 kB     00:00
update                                                                                                                                 | 1.9 kB     00:00
update/primary_db                                                                                                                      | 483 kB     00:00
Setting up Update Process
Resolving Dependencies