CentOS6.5默认Python版本升级到python2.7.5

### CentOS6.5系统自带版本是python2.6.6,升级至python2.7.5操做以下:python

# wget https://www.python.org/ftp/python/2.7.5/Python-2.7.5.tgz  //没法下载时自行官网下载django

# tar zxvf Python-2.7.5.tgzvim

# cd Python2.7.5python2.7

./configure --prefix=/usr/local/python2.7 --enable-unicode=ucs4--enable-shared  ide

# make && make install测试

# cd /usr/bin/ui

# ls -l |grep pythonthis

# mv python python.backspa

# ln -sv /usr/local/python2.7/bin/python/usr/bin/pythoncode

# cp /usr/local/python2.7/lib/libpython2.7.so.1.0 /usr/local/lib

# cd /usr/local/lib

# ln -s libpython2.7.so.1.0 libpython2.7.so

# whereis libpython2.7.so.1.0

libpython2.7.so.1: /usr/local/lib/libpython2.7.so.1.0   //显示即OK

# vim /etc/ld.so.conf.d/ python2.7.conf

/usr/local/lib      //添加此内容

# ldconfig

# ldconfig -v |grep libpython*     //查看连接库信息

      libpython2.7.so.1.0 -> libpython2.7.so.1.0

      libpython2.6.so.1.0 -> libpython2.6.so.1.0

# python -V      //测试成功显示以下

Python 2.7.5

### FAQ

1)报错:django.core.exceptions.ImproperlyConfigured: Error loading MySQLdbmodule: libpython2.7.so.1.0: cannot open shared object file: No such file ordirectory

解决:编译时须要添加:--enable-unicode=ucs4--enable-shared

2)报错:python: error while loading shared libraries: libpython2.7.so.1.0:cannot open shared object file: No such file or directory

解决:配置可共享的动态连接库

3)因为默认版本是Python2.6修改为Python2.7之后yum安装软件时会报问题,例如:

here was a problem importing one of thePython modules required to run yum. The error leading to this problem was:

No module named yum ……It's possible that the above module doesn't match the currentversion of Python, which is:

2.7.5

解决:# vim /usr/bin/yum,修改第一行为:#!/usr/bin/python2.6    //即便用系统原来的python2.6版本