centos升级python(从2.6.6升级到2.7.8)
***先安装readline,否则升级后python回退和方向键不能使用
yum install readline-devel.x86_64
2.#tar zxvf Python-2.7.8.tgz
3.#cd Python-2.7.8
在编译前先在/usr/local建一个文件夹python27
4.#./configure --enable-shared --prefix=/usr/local/python27
3.#cd Python-2.7.8
在编译前先在/usr/local建一个文件夹python27
4.#./configure --enable-shared --prefix=/usr/local/python27
如果有错误no acceptable C compiler found in $PATH,安装gcc:#yum install gcc
#make
#make install
此时没有覆盖老版本,再将原来/usr/bin/python链接改为别的名字
#mv /usr/bin/python /usr/bin/python_old
再建立新版本python的链接
#ln -s /usr/local/python27/bin/python2.7 /usr/bin/python
#make
#make install
此时没有覆盖老版本,再将原来/usr/bin/python链接改为别的名字
#mv /usr/bin/python /usr/bin/python_old
再建立新版本python的链接
#ln -s /usr/local/python27/bin/python2.7 /usr/bin/python
#ln -s /usr/local/python27/lib/libpython2.7.so /usr/lib64/libpython2.7.so (64位系统)
#ln -s /usr/local/python27/lib/libpython2.7.so /usr/lib/libpython2.7.so (32位系统)
#ln -s /usr/local/python27/lib/libpython2.7.so /usr/lib/libpython2.7.so (32位系统)
这个时候yum变得不可用,要修改yum,把python修改成原来的老版本
#vi /usr/bin/yum
"#!/usr/bin/python" 修改为“#!/usr/bin/python2.6”
(之
后输入python查看信息,如果提示error while loading shared libraries:
libpython2.7.so.1.0: cannot open shared object file: No such file or
directory,解决办法:
#vi /etc/ld.so.conf.d/python2.7.conf
加入/usr/local/python27/lib
保存退出后执行
#ldconfig
)
参考:http://www.linuxidc.com/Linux/2013-03/81117.htm