查看python的版本
[root@localhost ~] python -V
Python 2.4.3
Python 2.4.3
1.先安装GCC
yum -y install gcc
2.下载Python-2.7.2
[root@localhost ~] wget http://python.org/ftp/python/2.7.2/Python-2.7.2.tar.bz2
3.解压Python-2.7.2
[root@localhost ~] tar -jxvf Python-2.7.2.tar.bz2
4.进入刚解压后的文件夹(可使用命令):
[root@localhost ~] cd Python-2.7.2
5.安装
[root@localhost Python-2.7.2] ./configure
[root@localhost Python-2.7.2] make all
[root@localhost Python-2.7.2] make install
[root@localhost Python-2.7.2] make clean
[root@localhost Python-2.7.2] make distclean
[root@localhost Python-2.7.2] make all
[root@localhost Python-2.7.2] make install
[root@localhost Python-2.7.2] make clean
[root@localhost Python-2.7.2] make distclean
6.查看版本信息
/usr/local/bin/python2.7 -V
遇到错误:
python: error while loading shared libraries: libpython2.7.so.1.0:
cannot open shared object file: No such file or
解决方案:
新建下面文件
vim /etc/ld.so.conf.d/python2.7.conf
加入内容:
/usr/local/lib
保存退出后运行:
ldconfig
再次执行 python,问题成功解决。
7.建立软连接,使系统默认的python指向python2.7
正常情况下即使python2.7安装成功后,系统默认指向的python仍然是2.4.3(也可能是2.6版本)版本,考虑到yum是基于python2.4.3才能正常工作,不敢轻易卸载。
如何实现将系统默认的python指向到2.7版本呢?
mv /usr/bin/python /usr/bin/python2.4
ln -s /usr/local/bin/python2.7 /usr/bin/python
ln -s /usr/local/bin/python2.7 /usr/bin/python
检验python指向是否成功
python -V
8.解决系统python软链接指向python2.7版本后,yum不能正常工作
vi /usr/bin/yum
将文件头部的
#!/usr/bin/python
改成
#!/usr/bin/python2.4