1、下载
可从 http://www.python.org/进行下载
wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tar.bz2
2、解压
tar jxvf Python-2.7.2.tar.bz2
3.进入目录安装:
./configure --prefix=/usr/local/Python2.7 --enable-shared
make
make install
当出现 libpython2.7.so.1.0的错误时:
[root@CNC-BJ-5-3N1 bin]# ./python
./python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
[root@CNC-BJ-5-3N1 bin]# pwd
/usr/local/Python2.7/bin
[root@CNC-BJ-5-3N1 bin]# /usr/local/Python2.7/bin/python2.7
/usr/local/Python2.7/bin/python2.7: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
[root@CNC-BJ-5-3N1 bin]# pwd
/usr/local/Python2.7/bin
/usr/local/Python2.7/lib
libpython2.7.so.1.0的错误时的 解决办法:
(2) vi /etc/ld.so.conf 添加/usr/local/Python2.7/lib
/sbin/ldconfig
/sbin/ldconfig -v
参考:
http://www.cnblogs.com/amboyna/archive/2008/02/06/1065322.html
(3) 使用新安装的python:
mv /usr/bin/python /usr/bin/python.bak
ln -s /usr/local/Python2.7/bin/python2.7 /usr/bin/python
(4)因为yum默认的是使用python2.4,为了使yum命令能正确执行,需要修改
[root@CNC-BJ-5-3N1 bin]# vi yum
将#!/usr/bin/python 改为 #!/usr/bin/python2.4