最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[记录]CentOS 6中Python从2.6升级到2.7

CentOS crifan 3409浏览 0评论

折腾:

[记录]CentOS中安装和使用virtualenv

期间,要去把CentOS 6中的Python 2.6,升级到Python 2.7

但是要确保:

好像有人提到的:yum依赖于python 2.6

所以就是:

由于系统其它一些功能,要依赖于python 2.6

所以要升级Python 到2.7

却还要保证,不影响系统的其它功能,比如yum

centos 6 yum install python 2.7

CENTOS 6.5 安装 Python 2.7 总结 – digwtx – SegmentFault

Installing python 2.7 on centos 6.3. Follow this sequence exactly for centos machine only · h2oai/h2o-2 Wiki

CentOS yum安装或升级Python到2.7.5教程-CentOS-操作系统-壹聚教程网

CentOs 6.x 升级 Python 版本 | ruiaylin’s Blog

Centos 6.4 python 2.6 升级到 2.7 – Just Coding! – 博客频道 – CSDN.NET

阿里云yum升级python2.7 CentOS默认自带pyton2.6 一介布衣

然后尝试去安装:

直接去:

yum install -y python27

是不行的:

 jiandaoweixin yum install -y python27
Loaded plugins: security
Setting up Install Process
base                                                                                                            | 3.7 kB     00:00     
elrepo                                                                                                          | 2.9 kB     00:00     
epel                                                                                                            | 4.3 kB     00:00     
epel/primary_db                                                                                                 | 5.9 MB     00:05     
extras                                                                                                          | 3.4 kB     00:00     
updates                                                                                                         | 3.4 kB     00:00     
updates/primary_db                                                                                              | 1.4 MB     00:01     
No package python27 available.
Error: Nothing to do

只有先去:

yum install -y centos-release-SCL

 jiandaoweixin yum install -y centos-release-SCL
Loaded plugins: security
Setting up Install Process
Resolving Dependencies

<div–<> Running transaction check

<div–<-> Package centos-release-scl-rh.noarch 0:2-3.el6.centos will be installed

<div–<> Finished Dependency Resolution

Dependencies Resolved
=======================================================================================================================================
 Package                                  Arch                      Version                            Repository                 Size
=======================================================================================================================================
Installing:
 centos-release-scl-rh                    noarch                    2-3.el6.centos                     extras                     12 k
Transaction Summary
=======================================================================================================================================
Install       1 Package(s)
Total download size: 12 k
Installed size: 19 k
Downloading Packages:
centos-release-scl-rh-2-3.el6.centos.noarch.rpm                                                                 |  12 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : centos-release-scl-rh-2-3.el6.centos.noarch                                                                         1/1 
  Verifying  : centos-release-scl-rh-2-3.el6.centos.noarch                                                                         1/1 
Installed:
  centos-release-scl-rh.noarch 0:2-3.el6.centos                                                                                        
Complete!

再去:

yum install -y python27

 jiandaoweixin yum install -y python27          
Loaded plugins: security
Setting up Install Process
http://mirror.centos.org/centos/6/sclo/x86_64/rh/repodata/repomd.xml: [Errno 12] Timeout on http://mirror.centos.org/centos/6/sclo/x86_64/rh/repodata/repomd.xml: (28, ‘Connection time-out’)
Trying other mirror.
Error: Cannot retrieve repository metadata (repomd.xml) for repository: centos-sclo-rh. Please verify its path and try again
 jiandaoweixin yum install -y python27
Loaded plugins: security
Setting up Install Process
centos-sclo-rh                                                                                                  | 2.9 kB     00:00     
centos-sclo-rh/primary_db                                                                                       | 1.3 MB     00:37     
Resolving Dependencies

<div–<> Running transaction check

<div–<-> Package python27.x86_64 0:1.1-25.el6 will be installed

<div–<> Processing Dependency: python27-runtime for package: python27-1.1-25.el6.x86_64

<div–<> Processing Dependency: python27-python-wheel for package: python27-1.1-25.el6.x86_64

<div–<> Processing Dependency: python27-python-werkzeug for package: python27-1.1-25.el6.x86_64

<div–<> Processing Dependency: python27-python-virtualenv for package: python27-1.1-25.el6.x86_64

<div–<> Processing Dependency: python27-python-sqlalchemy for package: python27-1.1-25.el6.x86_64

<div–<> Processing Dependency: python27-python-sphinx for package: python27-1.1-25.el6.x86_64

<div–<> Processing Dependency: python27-python-simplejson for package: python27-1.1-25.el6.x86_64

<div–<> Processing Dependency: python27-python-setuptools for package: python27-1.1-25.el6.x86_64

<div–<> Processing Dependency: python27-python-pip for package: python27-1.1-25.el6.x86_64

<div–<> Processing Dependency: python27-python-nose for package: python27-1.1-25.el6.x86_64

<div–<> Processing Dependency: python27-python-jinja2 for package: python27-1.1-25.el6.x86_64

<div–<> Processing Dependency: python27-python for package: python27-1.1-25.el6.x86_64

<div–<> Running transaction check

<div–<-> Package python27-python.x86_64 0:2.7.8-16.el6 will be installed

<div–<> Processing Dependency: python27-python-libs(x86-64) = 2.7.8-16.el6 for package: python27-python-2.7.8-16.el6.x86_64

<div–<> Processing Dependency: libpython2.7.so.1.0()(64bit) for package: python27-python-2.7.8-16.el6.x86_64

<div–<-> Package python27-python-jinja2.noarch 0:2.6-10.sc1.el6 will be installed

<div–<> Processing Dependency: python27-python-babel >= 0.8 for package: python27-python-jinja2-2.6-10.sc1.el6.noarch

<div–<> Processing Dependency: python27-python-markupsafe for package: python27-python-jinja2-2.6-10.sc1.el6.noarch

<div–<-> Package python27-python-nose.noarch 0:1.3.0-1.sc1.el6 will be installed

<div–<-> Package python27-python-pip.noarch 0:7.1.0-2.el6 will be installed

<div–<-> Package python27-python-setuptools.noarch 0:0.9.8-3.el6 will be installed

<div–<-> Package python27-python-simplejson.x86_64 0:3.2.0-2.el6 will be installed

<div–<-> Package python27-python-sphinx.noarch 0:1.1.3-7.sc1.el6 will be installed

<div–<> Processing Dependency: python27-python-pygments for package: python27-python-sphinx-1.1.3-7.sc1.el6.noarch

<div–<> Processing Dependency: python27-python-docutils for package: python27-python-sphinx-1.1.3-7.sc1.el6.noarch

<div–<-> Package python27-python-sqlalchemy.x86_64 0:0.7.9-3.sc1.el6 will be installed

<div–<-> Package python27-python-virtualenv.noarch 0:13.1.0-1.el6 will be installed

<div–<> Processing Dependency: python27-python-devel for package: python27-python-virtualenv-13.1.0-1.el6.noarch

<div–<-> Package python27-python-werkzeug.noarch 0:0.8.3-5.sc1.el6 will be installed

<div–<-> Package python27-python-wheel.noarch 0:0.24.0-2.el6 will be installed

<div–<-> Package python27-runtime.x86_64 0:1.1-25.el6 will be installed

<div–<> Running transaction check

<div–<-> Package python27-python-babel.noarch 0:0.9.6-7.sc1.el6 will be installed

<div–<-> Package python27-python-devel.x86_64 0:2.7.8-16.el6 will be installed

<div–<> Processing Dependency: scl-utils-build for package: python27-python-devel-2.7.8-16.el6.x86_64

<div–<-> Package python27-python-docutils.noarch 0:0.11-2.el6 will be installed

<div–<-> Package python27-python-libs.x86_64 0:2.7.8-16.el6 will be installed

<div–<-> Package python27-python-markupsafe.x86_64 0:0.11-11.sc1.el6 will be installed

<div–<-> Package python27-python-pygments.noarch 0:1.5-2.sc1.el6 will be installed

<div–<> Running transaction check

<div–<-> Package scl-utils-build.x86_64 0:20120927-27.el6_6 will be installed

<div–<> Finished Dependency Resolution

Dependencies Resolved
=======================================================================================================================================
 Package                                   Arch                  Version                           Repository                     Size
=======================================================================================================================================
Installing:
 python27                                  x86_64                1.1-25.el6                        centos-sclo-rh                5.2 k
Installing for dependencies:
 python27-python                           x86_64                2.7.8-16.el6                      centos-sclo-rh                 82 k
 python27-python-babel                     noarch                0.9.6-7.sc1.el6                   centos-sclo-rh                1.4 M
 python27-python-devel                     x86_64                2.7.8-16.el6                      centos-sclo-rh                387 k
 python27-python-docutils                  noarch                0.11-2.el6                        centos-sclo-rh                1.6 M
 python27-python-jinja2                    noarch                2.6-10.sc1.el6                    centos-sclo-rh                550 k
 python27-python-libs                      x86_64                2.7.8-16.el6                      centos-sclo-rh                5.7 M
 python27-python-markupsafe                x86_64                0.11-11.sc1.el6                   centos-sclo-rh                 24 k
 python27-python-nose                      noarch                1.3.0-1.sc1.el6                   centos-sclo-rh                290 k
 python27-python-pip                       noarch                7.1.0-2.el6                       centos-sclo-rh                1.5 M
 python27-python-pygments                  noarch                1.5-2.sc1.el6                     centos-sclo-rh                801 k
 python27-python-setuptools                noarch                0.9.8-3.el6                       centos-sclo-rh                423 k
 python27-python-simplejson                x86_64                3.2.0-2.el6                       centos-sclo-rh                174 k
 python27-python-sphinx                    noarch                1.1.3-7.sc1.el6                   centos-sclo-rh                1.1 M
 python27-python-sqlalchemy                x86_64                0.7.9-3.sc1.el6                   centos-sclo-rh                2.1 M
 python27-python-virtualenv                noarch                13.1.0-1.el6                      centos-sclo-rh                1.7 M
 python27-python-werkzeug                  noarch                0.8.3-5.sc1.el6                   centos-sclo-rh                555 k
 python27-python-wheel                     noarch                0.24.0-2.el6                      centos-sclo-rh                 76 k
 python27-runtime                          x86_64                1.1-25.el6                        centos-sclo-rh                1.0 M
 scl-utils-build                           x86_64                20120927-27.el6_6                 base                           17 k
Transaction Summary
=======================================================================================================================================
Install      20 Package(s)
Total download size: 20 M
Installed size: 75 M
Downloading Packages:
(1/20): python27-1.1-25.el6.x86_64.rpm                                                                          | 5.2 kB     00:00     
(2/20): python27-python-2.7.8-16.el6.x86_64.rpm                                                                 |  82 kB     00:04     
(3/20): python27-python-babel-0.9.6-7.sc1.el6.noarch.rpm                                                        | 1.4 MB     00:38     
(4/20): python27-python-devel-2.7.8-16.el6.x86_64.rpm                                                           | 387 kB     00:16     
(5/20): python27-python-docutils-0.11-2.el6.noarch.rpm                                                          | 1.6 MB     00:33     
(6/20): python27-python-jinja2-2.6-10.sc1.el6.noarch.rpm                                                        | 550 kB     00:10     
(7/20): python27-python-libs-2.7.8-16.el6.x86_64.rpm                                                            | 5.7 MB     04:39     
(8/20): python27-python-markupsafe-0.11-11.sc1.el6.x86_64.rpm                                                   |  24 kB     00:00     
(9/20): python27-python-nose-1.3.0-1.sc1.el6.noarch.rpm                                                         | 290 kB     00:12     
http://mirror.centos.org/centos/6/sclo/x86_64/rh/python27/python27-python-pip-7.1.0-2.el6.noarch.rpm: [Errno 12] Timeout on http://mirror.centos.org/centos/6/sclo/x86_64/rh/python27/python27-python-pip-7.1.0-2.el6.noarch.rpm: (28, ‘Operation too slow. Less than 1 bytes/sec transfered the last 3 seconds’)
Trying other mirror.
(11/20): python27-python-pygments-1.5-2.sc1.el6.noarch.rpm                                                      | 801 kB     00:35     
(12/20): python27-python-setuptools-0.9.8-3.el6.noarch.rpm                                                      | 423 kB     00:22     
(13/20): python27-python-simplejson-3.2.0-2.el6.x86_64.rpm                                                      | 174 kB     00:11     
http://mirror.centos.org/centos/6/sclo/x86_64/rh/python27/python27-python-sphinx-1.1.3-7.sc1.el6.noarch.rpm: [Errno 12] Timeout on http://mirror.centos.org/centos/6/sclo/x86_64/rh/python27/python27-python-sphinx-1.1.3-7.sc1.el6.noarch.rpm: (28, ‘Operation too slow. Less than 1 bytes/sec transfered the last 3 seconds’)
Trying other mirror.
(15/20): python27-python-sqlalchemy-0.7.9-3.sc1.el6.x86_64.rpm                                                  | 2.1 MB     02:38     
(16/20): python27-python-virtualenv-13.1.0-1.el6.noarch.rpm                                                     | 1.7 MB     02:36     
(17/20): python27-python-werkzeug-0.8.3-5.sc1.el6.noarch.rpm                                                    | 555 kB     00:33     
(18/20): python27-python-wheel-0.24.0-2.el6.noarch.rpm                                                          |  76 kB     00:02     
http://mirror.centos.org/centos/6/sclo/x86_64/rh/python27/python27-runtime-1.1-25.el6.x86_64.rpm: [Errno 12] Timeout on http://mirror.centos.org/centos/6/sclo/x86_64/rh/python27/python27-runtime-1.1-25.el6.x86_64.rpm: (28, ‘connect() timed out!’)
Trying other mirror.
(20/20): scl-utils-build-20120927-27.el6_6.x86_64.rpm                                                           |  17 kB     00:00     
Error Downloading Packages:
  python27-python-sphinx-1.1.3-7.sc1.el6.noarch: failure: python27/python27-python-sphinx-1.1.3-7.sc1.el6.noarch.rpm from centos-sclo-rh: [Errno 256] No more mirrors to try.
  python27-runtime-1.1-25.el6.x86_64: failure: python27/python27-runtime-1.1-25.el6.x86_64.rpm from centos-sclo-rh: [Errno 256] No more mirrors to try.
  python27-python-pip-7.1.0-2.el6.noarch: failure: python27/python27-python-pip-7.1.0-2.el6.noarch.rpm from centos-sclo-rh: [Errno 256] No more mirrors to try.

 很明显,最后还是找不到镜像而失败。。。

之前出错了。

重新根据:

CentOs 6.x 升级 Python 版本 | ruiaylin’s Blog

去操作:

yum -y update

 html yum update -y
Loaded plugins: security
Setting up Update Process
base                                                                                                             | 3.7 kB     00:00     
centos-sclo-rh                                                                                                   | 2.9 kB     00:00     
elrepo                                                                                                           | 2.9 kB     00:00     
epel                                                                                                             | 4.3 kB     00:00     
extras                                                                                                           | 3.4 kB     00:00     
updates                                                                                                          | 3.4 kB     00:00     
Resolving Dependencies

<div–<> Running transaction check

<div–<-> Package GeoIP-GeoLite-data.noarch 0:2015.12-1.el6 will be updated

<div–<-> Package GeoIP-GeoLite-data.noarch 0:2016.07-1.el6 will be an update

<div–<-> Package GeoIP-GeoLite-data-extra.noarch 0:2015.12-1.el6 will be updated

<div–<-> Package GeoIP-GeoLite-data-extra.noarch 0:2016.07-1.el6 will be an update

<div–<-> Package initscripts.x86_64 0:9.03.53-1.el6.centos will be updated

<div–<-> Package initscripts.x86_64 0:9.03.53-1.el6.centos.1 will be an update

<div–<-> Package kernel.x86_64 0:2.6.32-642.3.1.el6 will be installed

<div–<-> Package kernel-devel.x86_64 0:2.6.32-642.3.1.el6 will be installed

<div–<-> Package kernel-firmware.noarch 0:2.6.32-642.1.1.el6 will be updated

<div–<-> Package kernel-firmware.noarch 0:2.6.32-642.3.1.el6 will be an update

<div–<-> Package kernel-headers.x86_64 0:2.6.32-642.1.1.el6 will be updated

<div–<-> Package kernel-headers.x86_64 0:2.6.32-642.3.1.el6 will be an update

<div–<-> Package libcgroup.x86_64 0:0.40.rc1-17.el6_7 will be updated

。。。
  Verifying  : libxml2-2.7.6-21.el6.x86_64                                                                                        32/32 
Installed:
  kernel.x86_64 0:2.6.32-642.3.1.el6                              kernel-devel.x86_64 0:2.6.32-642.3.1.el6                             
Updated:
  GeoIP-GeoLite-data.noarch 0:2016.07-1.el6                        GeoIP-GeoLite-data-extra.noarch 0:2016.07-1.el6                     
  initscripts.x86_64 0:9.03.53-1.el6.centos.1                      kernel-firmware.noarch 0:2.6.32-642.3.1.el6                         
  kernel-headers.x86_64 0:2.6.32-642.3.1.el6                       libcgroup.x86_64 0:0.40.rc1-18.el6_8                                
  libtiff.x86_64 0:3.9.4-18.el6_8                                  libxml2.x86_64 0:2.7.6-21.el6_8.1                                   
  libxml2-python.x86_64 0:2.7.6-21.el6_8.1                         mdadm.x86_64 0:3.3.4-1.el6_8.5                                      
  nss-softokn.x86_64 0:3.14.3-23.3.el6_8                           nss-softokn-freebl.x86_64 0:3.14.3-23.3.el6_8                       
  tar.x86_64 2:1.23-15.el6_8                                       tzdata.noarch 0:2016f-1.el6                                         
  yum.noarch 0:3.2.29-75.el6.centos                               
Complete!

[已解决]CentOS中查看某个包的依赖

的确是yum需要python 2.6

 html yuyum groupinstall -y ‘development tools’
Loaded plugins: security
Setting up Group Process
Package flex-2.5.35-9.el6.x86_64 already installed and latest version
Package gcc-4.4.7-17.el6.x86_64 already installed and latest version
Package redhat-rpm-config-9.0.3-51.el6.centos.noarch already installed and latest version
Package rpm-build-4.8.0-55.el6.x86_64 already installed and latest version
。。。
Package swig-1.3.40-6.el6.x86_64 already installed and latest version
Warning: Group development does not have any packages.
No packages in any requested group available to install or update
 html yum install -y zlib-devel bzip2-devel openssl-devel xz-libs wget
Loaded plugins: security
Setting up Install Process
Package zlib-devel-1.2.3-29.el6.x86_64 already installed and latest version
Package xz-libs-4.999.9-0.5.beta.20091007git.el6.x86_64 already installed and latest version
Package wget-1.12-8.el6.x86_64 already installed and latest version
Resolving Dependencies

<div–<> Running transaction check

<div–<-> Package bzip2-devel.x86_64 0:1.0.5-7.el6_0 will be installed

<div–<-> Package openssl-devel.x86_64 0:1.0.1e-48.el6_8.1 will be installed

。。。
  Verifying  : bzip2-devel-1.0.5-7.el6_0.x86_64                                                                                     7/7 
Installed:
  bzip2-devel.x86_64 0:1.0.5-7.el6_0                              openssl-devel.x86_64 0:1.0.1e-48.el6_8.1                             
Dependency Installed:
  keyutils-libs-devel.x86_64 0:1.4-5.el6       krb5-devel.x86_64 0:1.10.3-57.el6          libcom_err-devel.x86_64 0:1.41.12-22.el6      
  libselinux-devel.x86_64 0:2.0.94-7.el6       libsepol-devel.x86_64 0:2.0.41-4.el6      
Complete!

本来打算去下载2.8的,看到主页中:

Index of /ftp/python/

有2.7.9,所以去下载最新的2.7.12

wget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tar.xz

Linux CentOS 6.7上安装Python 2.7.12 – 简书

CentOS6.5安装Python2.7和Pip-爱编程

setuptools 25.2.0 : Python Package Index

makefile – Difference in details between "make install" and "make altinstall" – Stack Overflow

 ~ wget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tar.xz

<div–<2016-08-15 10:47:33–  https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tar.xz

Resolving www.python.org… 151.101.36.223, 2a04:4e42:4::223
Connecting to www.python.org|151.101.36.223|:443… connected.
HTTP request sent, awaiting response… 200 OK
Length: 12390820 (12M) [application/octet-stream]
Saving to: ython-2.7.12.tar.xz
100%[==============================================================================================>] 12,390,820  16.5K/s   in 15m 55s 
2016-08-15 11:03:29 (12.7 KB/s) – ython-2.7.12.tar.xzsaved [12390820/12390820]

xz -d Python-2.7.8.tar.xz  

tar -xvf Python-2.7.8.tar

 

make

make altinstall

 Python-2.7.12 python2.7 -V
zsh: command not found: python7
 Python-2.7.12 lsls /usr/local/bin/python2.7
/usr/local/bin/python2.7
 Python-2.7.12 ls /usr/local/bin/python2.7 -l
-rwxr-xr-x 1 root root 6294745 Aug 15 11:12 /usr/local/bin/python2.7
 Python-2.7.12 ls /usr/local/bin/python2.* -l
-rwxr-xr-x 1 root root 6294745 Aug 15 11:12 /usr/local/bin/python2.7
-rwxr-xr-x 1 root root    1687 Aug 15 11:13 /usr/local/bin/python2.7-config
 Python-2.7.12 /usr/local/bin/python2.7 -V
Python 2.7.12
 Python-2.7.12 export PATH="/usr/local/bin:$PATH"  
 Python-2.7.12 pypython2.7 -V
Python 2.7.12

setuptools 25.2.0 : Python Package Index

->

setuptools-25.2.0.tar.gz (md5)

->

https://pypi.python.org/packages/9f/32/81c324675725d78e7f6da777483a3453611a427db0145dfb878940469692/setuptools-25.2.0.tar.gz#md5=a0dbb65889c46214c691f6c516cf959c

->

https://pypi.python.org/packages/9f/32/81c324675725d78e7f6da777483a3453611a427db0145dfb878940469692/setuptools-25.2.0.tar.gz

->

wget –no-check-certificate https://pypi.python.org/packages/9f/32/81c324675725d78e7f6da777483a3453611a427db0145dfb878940469692/setuptools-25.2.0.tar.gz

<div–<2016-08-15 11:20:06–  https://pypi.python.org/packages/9f/32/81c324675725d78e7f6da777483a3453611a427db0145dfb878940469692/setuptools-25.2.0.tar.gz

Resolving pypi.python.org… 151.101.16.223, 2a04:4e42:4::223
Connecting to pypi.python.org|151.101.16.223|:443… connected.
HTTP request sent, awaiting response… 200 OK
Length: 612103 (598K) [binary/octet-stream]
Saving to: etuptools-25.2.0.tar.gz
100%[==============================================================================================>] 612,103     36.9K/s   in 23s     
2016-08-15 11:20:33 (26.4 KB/s) – etuptools-25.2.0.tar.gzsaved [612103/612103]
 Python-2.7.12 tatar xf setuptools-25.2.0.tar.gz
 setuptools-25.2.0 pypython2.7 setup.py install
running install
running bdist_egg
running egg_info
writing requirements to setuptools.egg-info/requires.txt
。。。
Installing easy_install-2.7 script to /usr/local/bin
Installed /usr/local/lib/python2.7/site-packages/setuptools-25.2.0-py2.7.egg
Processing dependencies for setuptools==25.2.0
Finished processing dependencies for setuptools==25.2.0
 setuptools-25.2.0  
 setuptools-25.2.0 curl https://bootstrap.pypa.io/get-pip.py | python2.7 – 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1488k  100 1488k    0     0  18921      0  0:01:20  0:01:20 –:–:– 39262
Collecting pip
  Using cached pip-8.1.2-py2.py3-none-any.whl
Collecting wheel
  Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
    100% || 71kB 55kB/s 
Installing collected packages: pip, wheel
Successfully installed pip-8.1.2 wheel-0.29.0
 setuptools-25.2.0 which python
/usr/bin/python
 setuptools-25.2.0 python -V
Python 2.6.6
 setuptools-25.2.0 pyls /usr/bin/py* -l
-rwxr-xr-x 1 root root   78 Jul 24  2015 /usr/bin/pydoc
-rwxr-xr-x 2 root root 9032 Jul 24  2015 /usr/bin/python
lrwxrwxrwx 1 root root    6 Jun  2 16:28 /usr/bin/python2 -> python
-rwxr-xr-x 2 root root 9032 Jul 24  2015 /usr/bin/python2.6
 setuptools-25.2.0 ln -s /usr/local/bin/python2.7  /usr/bin/python
ln: creating symbolic link `/usr/bin/python’: File exists
 setuptools-25.2.0 rmrm /usr/bin/python
 setuptools-25.2.0 ln -s /usr/local/bin/python2.7  /usr/bin/python  
 setuptools-25.2.0 lnpython -V                                      
 setuptools-25.2.0 lnls /usr/bin/py* -l                             
-rwxr-xr-x 1 root root   78 Jul 24  2015 /usr/bin/pydoc
lrwxrwxrwx 1 root root   24 Aug 15 11:45 /usr/bin/python -> /usr/local/bin/python2.7
lrwxrwxrwx 1 root root    6 Jun  2 16:28 /usr/bin/python2 -> python
-rwxr-xr-x 1 root root 9032 Jul 24  2015 /usr/bin/python2.6
 setuptools-25.2.0 python -V
Python 2.7.12
 setuptools-25.2.0 which python
/usr/bin/python

which yum

vi /usr/bin/yum

把:

将第一行的

#!/usr/bin/python

改为

#!/usr/bin/python2.6

如图:

 setuptools-25.2.0 cat /usr/bin/yum
#!/usr/bin/python2.6
。。。

[总结]

1.更新系统库

yum -y update
yum groupinstall -y ‘development tools’

安装 python 工具需要的额外软件包 SSL, bz2, zlib

yum install -y zlib-devel bzip2-devel openssl-devel xz-libs wget

注:

后来又需要sqlite,所以也最好加航:

yum install -y sqlite-devel

2.找到Python 2的最新的版本和下载地址:

Index of /ftp/python/

->中,找到Python 2最新的版本,此处是2.7.12:

https://www.python.org/ftp/python/2.7.12/

-》

里面的要下载的是:

https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tar.xz

-》

去通过源码下载和解压Python:

wget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tar.xz
xz -d Python-2.7.12.tar.xz
tar -xvf Python-2.7.12.tar

通过源码安装Python:

cd Python-2.7.12
./configure –prefix=/usr/local
make
make altinstall

确认已经安装成功,查看版本:

export PATH="/usr/local/bin:$PATH"
python2.7 -V

3.找到最新版本的setuptools:

setuptools 25.2.0 : Python Package Index

-》

找到最新版本,此处是25.2.0:

setuptools-25.2.0.tar.gz (md5)

右击可以拷贝下载链接地址:

https://pypi.python.org/packages/9f/32/81c324675725d78e7f6da777483a3453611a427db0145dfb878940469692/setuptools-25.2.0.tar.gz#md5=a0dbb65889c46214c691f6c516cf959c

-》去掉md的后缀,变为:

https://pypi.python.org/packages/9f/32/81c324675725d78e7f6da777483a3453611a427db0145dfb878940469692/setuptools-25.2.0.tar.gz

-》下载setuptools的源码并安装:

wget –no-check-certificate https://pypi.python.org/packages/9f/32/81c324675725d78e7f6da777483a3453611a427db0145dfb878940469692/setuptools-25.2.0.tar.gz
tar -xvf setuptools-25.2.0.tar.gz
cd setuptools-25.2.0
python2.7 setup.py install

下载和安装PIP:

curl https://bootstrap.pypa.io/get-pip.py | python2.7 –

4.设置默认Python为最新版本的Python:

rm /usr/bin/python
ln -s /usr/local/bin/python2.7  /usr/bin/python
ls -l /usr/bin/py*

注意:

此处应该是第三步的时候,直接食用make install而不是make altinstall

估计就可以自动让python 2.7变成默认的Python了。

就无需此步骤了。

5.修复yum

which yum
vi /usr/bin/yum

把:

将第一行的

#!/usr/bin/python

改为

#!/usr/bin/python2.6

转载请注明:在路上 » [记录]CentOS 6中Python从2.6升级到2.7

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.209 seconds, using 22.17MB memory