1.下载
https://www.python.org/downloads/release/python-2714/
linux平台的有两种,
Python 2.7 compressed source tarball (for Linux, Unix or OS X)
和
Python 2.7 bzipped source tarball (for Linux, Unix or OS X, more compressed)
第二种是压缩比较好的,在linux中用bzip2压缩的文件比较高,文件名一般为*.tar.bz2,
2. 解压,配置,编译
[root@mysql_slave]# tar -zxvf Python-2.7.14.tgz
[root@mysql_slave]# cd Python-2.7.14
[root@mysql_slave Python-2.7.14]# ./configure --prefix=/usr/local/python-2.7.14
[root@mysql_slave Python-2.7.14]# make
[root@mysql_slave Python-2.7.14]# make install
[root@mysql_slave local]# cd /usr/bin
[root@mysql_slave bin]# ln -s /usr/local/python-2.7.14/bin/python ./python
[root@mysql_slave ~]# python
Python 2.7.14 (default, Dec 17 2017, 04:25:22)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
5. 由于yum不支持ython2.7版本,使用yum会报错
[root@mysql_slave ~]# yum list gcc
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
No module named yum
Please install a package which provides this module, or
verify that the module is installed correctly.
It's possible that the above module doesn't match the
current version of Python, which is:
2.7.14 (default, Dec 17 2017, 04:25:22)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]
If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq
解决方法:
--查找python
[root@mysql_slave ~]# whereis python
python: /usr/bin/python2.6-config /usr/bin/python2.6 /usr/bin/python /usr/lib/python2.6 /usr/lib64/python2.6 /usr/local/bin/python2.7-config /usr/local/bin/python2.7 /usr/local/bin/python /usr/local/lib/python2.7 /usr/include/python2.6 /usr/share/man/man1/python.1.gz
--查找yum
[root@mysql_slave ~]# whereis yum
yum: /usr/bin/yum /etc/yum.conf /etc/yum /usr/share/man/man8/yum.8.gz
--修改yum,第一行改为2.6即可
[root@mysql_slave ~]# vi /usr/bin/yum
#!/usr/bin/python2.6