CentOS 6.3中,Python-2.7.3交互模式下方向键、退格键等出现乱码

 

#安装readline-devel

# yum install readline-devl
#重新安装python

1. 准备工作

下载源码包

# wget

如果没有安装make工具

~#rpm -qa|grep make

yum -y install gcc automake autoconf libtool make

安装zlib

yum install zlib-devel

安装openssl

yum install openssl*

安装bzip2依赖库

yum install -y bzip2*

2. 编译安装

cp Python-2.7.3.tar.bz2 /usr/src/

tar -jxvf Python-2.7.3.tar.bz2
vi Modules/Setup.dist

找到   

#SSL=/usr/local/ssl

#_ssl _ssl.c \
#       -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
#       -L$(SSL)/lib -lssl -lcrypto
......
#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz

 把注释去掉

 编译

./configure --prefix=/usr/local/python2.7

make all make install
make cleanmake distclean

 

建立python2.7 软链

~#mv /usr/bin/python /usr/bin/python.bak~#ln -s /usr/local/python2.7/bin/python2.7 /usr/bin/python2.7

~#ln -s /usr/bin/python2.7 /usr/bin/python

3. 解决yum无法使用的问题

 

~#yum update

There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:

   No module named yum

Please install a package which provides this module, or

verify that the module is installed correctly.

It's possible that the above module doesn't match the

current version of Python, which is:
2.7.3 (default, Dec 18 2013, 15:43:35)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]

If you cannot solve this problem yourself, please go to

the yum faq at:
 

 

 因为centos 6.3 下yum默认使用的是python2.6

 vi /usr/bin/yum

----------------------------------------------------
#!/usr/bin/python
import sys
try:
    import yum
except ImportError:
.......

 

修改为:

#!/usr/bin/python2.6........