Linux安装python2.7

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 ~]# 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



  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值