linux下将Python自带版本(2.6.6)升级到2.7.3
1.查看python版本
python
Python 2.6.6 (default, Mar 15 2019, 00:32:28)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
2.下载2.7.3版本
3.解压
tar xvf Python-2.7.3.tar.bz2
4.编译安装
./configure --prefix=/usr/local/python27
make
make install
安装过程中遇到no acceptable C compiler found in $PATH when installing python问题,yum安装依赖库gcc
yum install gcc
5.更改新版本Python链接
mv /usr/bin/python /usr/bin/python2.6.6
ln -s /usr/local/python27/bin/python /usr/bin/python #软链接
6.查看新版本
python
Python 2.7.3 (default, Mar 15 2019, 00:32:28)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
7.新安装python之后,yum无法使用,需要更改一下Python指定
修改/usr/bin/yum文件,将第一行的/usr/bin/python替换为/usr/bin/python2.6.6
vim /usr/bin/yum
#!/usr/bin/python2.6.6 #修改为旧版本
8.python执行出现退格键乱码问题
1)安装readline开发包
2)在新版本Python中重新编译Python
yum install readline-devel.x86_64
到python目录下重新编译,make install