Linux安装python2.7

来源:互联网 发布:房间4g网络信号差 编辑:程序博客网 时间:2024/06/09 23:43

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

3. 替换python默认版本

[root@mysql_slave local]# cd /usr/bin[root@mysql_slave bin]# ln -s /usr/local/python-2.7.14/bin/python ./python

4. 测试可用

[root@mysql_slave ~]# pythonPython 2.7.14 (default, Dec 17 2017, 04:25:22) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> 

5. 由于yum不支持ython2.7版本,使用yum会报错

[root@mysql_slave ~]# yum list gccThere was a problem importing one of the Python modulesrequired to run yum. The error leading to this problem was:   No module named yumPlease install a package which provides this module, orverify that the module is installed correctly.It's possible that the above module doesn't match thecurrent 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 pythonpython: /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 yumyum: /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