Centos 7从python2.7.5升级到python2.7.13环境实战

[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

 

 

 

 

 

 

 

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/54127.html

(0)
上一篇 2021年8月7日
下一篇 2021年8月7日

相关推荐

发表回复

登录后才能评论