Centos6安装Python2.7.13

1、查看当前系统中的 Python 版本

 [root@localhost ~]# python --version
 Python 2.6.6

2、检查 CentOS 版本

 [root@localhost ~]# cat /etc/redhat-release
 CentOS release 6.10 (Final)

3、安装所有的开发工具包

 [root@localhost ~]# yum groupinstall -y "Development tools"
 [root@localhost ~]# yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel

4、下载、编译和安装 Python 2.7.13

 [root@localhost ~]# wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz
 [root@localhost ~]# tar zxf Python-2.7.13.tgz
 [root@localhost ~]# cd Python-2.7.13
 [root@localhost Python-2.7.13]# ./configure
 [root@localhost Python-2.7.13]# make && make install
 ##默认 Python 2.7.13 会安装在 /usr/local/bin 目录下
 [root@localhost Python-2.7.13]# ll -tr /usr/local/bin/python*
 -rwxr-xr-x1root root 626156810月 1217:17 /usr/local/bin/python2.7
 -rwxr-xr-x1root root    168710月 1217:17 /usr/local/bin/python2.7-config
 lrwxrwxrwx 1root root       710月 1217:17 /usr/local/bin/python -> python2
 lrwxrwxrwx 1root root       910月 1217:17 /usr/local/bin/python2 -> python2.7
 lrwxrwxrwx 1root root      1610月 1217:17 /usr/local/bin/python2-config -> python2.7-config
 lrwxrwxrwx 1root root      1410月 1217:17 /usr/local/bin/python-config -> python2-config
 ##而系统自带的 Python 是在 /usr/bin 目录下
 [root@localhost Python-2.7.13]# ll -tr /usr/bin/python*
 -rwxr-xr-x. 2root root 48648月  182016/usr/bin/python2.6
 -rwxr-xr-x. 2root root 48648月  182016/usr/bin/python
 lrwxrwxrwx. 1root root    61月  252019/usr/bin/python2 -> python

5、更新系统默认 Python 版本

 ##先把系统默认的旧版 Python 重命名
 [root@localhost Python-2.7.13]# mv /usr/bin/python /usr/bin/python.old
 ##再删除系统默认的 python-config 软链接
 [root@localhost Python-2.7.13]# rm -f /usr/bin/python-config
 ##最后创建新版本的 Python 软链接
 [root@localhost Python-2.7.13]# ln -s /usr/local/bin/python /usr/bin/python
 ##以上步骤做完以后,目录 /usr/bin 下的 Python 应该是
 [root@localhost Python-2.7.13]# ll -tr /usr/bin/python*
 -rwxr-xr-x. 2root root 48648月  182016/usr/bin/python.old
 -rwxr-xr-x. 2root root 48648月  182016/usr/bin/python2.6
 lrwxrwxrwx. 1root root    61月  252019/usr/bin/python2 -> python
 lrwxrwxrwx  1root root   2110月 1217:20 /usr/bin/python -> /usr/local/bin/python

6、查看新的 Python 版本

 [root@localhost Python-2.7.13]# python --version
 Python 2.7.13
 ##返回 Python 2.7.13 为正常

7、为新版 Python 安装 setuptools

 [root@localhost Python-2.7.13]# wget https://bootstrap.pypa.io/ez_setup.py -O - | python
 ##setuptools 正确安装完成后,easy_install 命令就会被安装在 /usr/local/bin 目录下了

8、为新版 Python 安装 pip

 [root@localhost Python-2.7.13]# easy_install pip
 ##正确安装完成后,pip 命令就会被安装在 /usr/local/bin 目录下了

9、修改yum源,使其指向原来的版本

 [root@localhost Python-2.7.13]# vim /usr/bin/yum
  1#!/usr/bin/python2.6
 ##修改配置文件头部#!/usr/bin/python改为--->#!/usr/bin/python2.6

10、测试

 [root@localhost Python-2.7.13]# pip install distribute
 DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
 Collecting distribute
 Downloading https://files.pythonhosted.org/packages/5f/ad/1fde06877a8d7d5c9b60eff7de2d452f639916ae1d48f0b8f97bf97e570a/distribute-0.7.3.zip (145kB)
     |████████████████████████████████| 153kB 252kB/s 
 Requirement already satisfied: setuptools>=0.7 in/usr/local/lib/python2.7/site-packages/setuptools-33.1.1-py2.7.egg (from distribute) (33.1.1)
 Installing collected packages: distribute
 Running setup.py install fordistribute ... done
 Successfully installed distribute-0.7.3

关于运维学习、分享、交流,笔者开通了微信公众号【运维猫】,感兴趣的朋友可以关注下,欢迎加入,建立属于我们自己的小圈子,一起学运维知识。

有需要技术交流的小伙伴可以加我微信,期待与大家共同成长,本人微信:

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值