1年前 (2018-09-12) 網友投稿  python
文章評分 1 次,平均分 5.0
[[email protected] ~]# cat /etc/centos-release
    CentOS Linux release 7.4.1708 (Core)
[[email protected] ~]# python -V
    Python 2.7.5
[[email protected] ~]# 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
[[email protected] ~]# cd /home/
[[email protected] home]# wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz
[[email protected] home]# tar -zxvf Python-2.7.13.tgz
[[email protected] home]# yum install gcc* openssl openssl-devel ncurses-devel.x86_64  bzip2-devel sqlite-devel python-devel zlib

[[email protected] home]# cd Python-2.7.13/
[[email protected] Python-2.7.13]# ./configure --prefix=/usr/local  #  [配置]指定可執行文件、庫文件、配置文件、資源文件的安裝路徑。
[[email protected] Python-2.7.13]# make
[[email protected] Python-2.7.13]# make altinstall  # 不要使用make install,否則會覆蓋系統自帶python 

備份舊版本,連接新版本

[[email protected] Python-2.7.13]# mv /usr/bin/python /usr/bin/python2.7.5
[[email protected] 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
[[email protected] Python-2.7.13]# ln -s /usr/local/bin/python2.7 /usr/bin/python   # 增加連接
[[email protected] 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版本

[[email protected] 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版本)

[[email protected] 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呢

[[email protected] 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.
[[email protected] 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)

[[email protected] 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
[[email protected] Python-2.7.13]# vim /usr/bin/yum
    首行的#!/usr/bin/python 改為 #!/usr/bin/python2.7
[[email protected] Python-2.7.13]# vi /usr/libexec/urlgrabber-ext-down
    首行的#!/usr/bin/python 改為 #!/usr/bin/python2.7

 

 

 

 

 

 

 


//下面這個css和插件后臺設置的主題有關系,如果需要換樣式,則需要修改以下CSS名稱

  
 

除特別注明外,本站所有文章均為鐵匠運維網原創,轉載請注明出處來自http://www.kzrhud.live/22257.html

發表評論

暫無評論

切換注冊

登錄

忘記密碼 ?

您也可以使用第三方帳號快捷登錄

切換登錄

注冊

掃一掃二維碼分享
青海11选5开奖结果走势图