2个月前 (09-12)  python    抢沙发
文章评分 1 次,平均分 5.0
[root@tiejiang ~]# cat /etc/centos-release
    CentOS Linux release 7.4.1708 (Core)
[root@tiejiang ~]# python -V
    Python 2.7.5
[root@tiejiang ~]# ll -l /usr/bin/python*
    lrwxrwxrwx. 1 root root    7 Jan  9  2018 /usr/bin/python -> python2
    lrwxrwxrwx. 1 root root    9 Jan  9  2018 /usr/bin/python2 -> python2.7
    -rwxr-xr-x. 1 root root 7136 Aug  4  2017 /usr/bin/python2.7
[root@tiejiang ~]# cd /home/
[root@tiejiang home]# wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz
[root@tiejiang home]# tar -zxvf Python-2.7.13.tgz
[root@tiejiang home]# yum install gcc* openssl openssl-devel ncurses-devel.x86_64  bzip2-devel sqlite-devel python-devel zlib

[root@tiejiang home]# cd Python-2.7.13/
[root@tiejiang Python-2.7.13]# ./configure --prefix=/usr/local  #  [配置]指定可执行文件、库文件、配置文件、资源文件的安装路径。
[root@tiejiang Python-2.7.13]# make
[root@tiejiang Python-2.7.13]# make altinstall  # 不要使用make install,否则会覆盖系统自带python 

备份旧版本,连接新版本

[root@tiejiang Python-2.7.13]# mv /usr/bin/python /usr/bin/python2.7.5
[root@tiejiang Python-2.7.13]# ll -l /usr/bin/python*
    lrwxrwxrwx 1 root root    9 Aug 14 13:27 /usr/bin/python2 -> python2.7
    -rwxr-xr-x 1 root root 7216 Jul 13 21:07 /usr/bin/python2.7
    lrwxrwxrwx 1 root root    7 Aug 14 13:27 /usr/bin/python2.7.5 -> python2     # 改为2.7.5
    -rwxr-xr-x 1 root root 1835 Jul 13 21:07 /usr/bin/python2.7-config
    lrwxrwxrwx 1 root root   16 Aug 14 13:27 /usr/bin/python2-config -> python2.7-config
    lrwxrwxrwx 1 root root   14 Aug 14 13:27 /usr/bin/python-config -> python2-config
[root@tiejiang Python-2.7.13]# ln -s /usr/local/bin/python2.7 /usr/bin/python   # 增加连接
[root@tiejiang Python-2.7.13]# ll -l /usr/bin/python*
    lrwxrwxrwx 1 root root   24 Aug 14 13:32 /usr/bin/python -> /usr/local/bin/python2.7    # 新增的,并指向新安装的python
    lrwxrwxrwx 1 root root    9 Aug 14 13:27 /usr/bin/python2 -> python2.7
    -rwxr-xr-x 1 root root 7216 Jul 13 21:07 /usr/bin/python2.7
    lrwxrwxrwx 1 root root    7 Aug 14 13:27 /usr/bin/python2.7.5 -> python2
    -rwxr-xr-x 1 root root 1835 Jul 13 21:07 /usr/bin/python2.7-config
    lrwxrwxrwx 1 root root   16 Aug 14 13:27 /usr/bin/python2-config -> python2.7-config
    lrwxrwxrwx 1 root root   14 Aug 14 13:27 /usr/bin/python-config -> python2-config

再次检查python版本

[root@tiejiang Python-2.7.13]# python   #正常展示python2.7.13版本
    Python 2.7.13 (default, Aug 14 2018, 13:30:06) 
    [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.

若想访问老版本python(如2.7.5版本)

[root@tiejiang Python-2.7.13]# python2.7.5
    Python 2.7.5 (default, Jul 13 2018, 13:06:57) 
    [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.

题外话:python2, python2.7访问的是2.7.5还是2.7.13呢

[root@tiejiang Python-2.7.13]# python2.7
    Python 2.7.13 (default, Aug 14 2018, 13:30:06) 
    [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
[root@tiejiang Python-2.7.13]# python2
    Python 2.7.5 (default, Jul 13 2018, 13:06:57) 
    [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.

番外:yum的设置(系统预装的yum引用的老版本python)

[root@tiejiang Python-2.7.13]# yum -y install lrzsz
    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.13 (default, Aug 14 2018, 13:30:06) 
    [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]

    If you cannot solve this problem yourself, please go to 
    the yum faq at:
    http://yum.baseurl.org/wiki/Faq
[root@tiejiang Python-2.7.13]# vim /usr/bin/yum
    首行的#!/usr/bin/python 改为 #!/usr/bin/python2.7
[root@tiejiang Python-2.7.13]# vi /usr/libexec/urlgrabber-ext-down
    首行的#!/usr/bin/python 改为 #!/usr/bin/python2.7

 

 

 

 

 

 

 


//下面这个css和插件后台设置的主题有关系,如果需要换样式,则需要修改以下CSS名称

  
 

除特别注明外,本站所有文章均为铁匠运维网原创,转载请注明出处来自http://www.tiejiang.org/22257.html

关于

发表评论

暂无评论

切换注册

登录

忘记密码 ?

您也可以使用第三方帐号快捷登录

切换登录

注册

扫一扫二维码分享