### CentOS6.5系统自带版本是python2.6.6,升级至python2.7.5操作如下:
# wget https://www.python.org/ftp/python/2.7.5/Python-2.7.5.tgz //无法下载时自行官网下载
# tar zxvf Python-2.7.5.tgz
# cd Python2.7.5
./configure --prefix=/usr/local/python2.7 --enable-unicode=ucs4--enable-shared
# make && make install
# cd /usr/bin/
# ls -l |grep python
# mv python python.back
# ln -sv /usr/local/python2.7/bin/python/usr/bin/python
# 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版本