升级Python到2.7

升级Python,只需要简单的几步:

  1. 查看系统当前python版本

    1
    2
    3
    [root@localhost ~]# python -V
    Python 2.6.6
    [root@localhost ~]#
  2. 下载新版本的python2.7

    1
    [root@localhost ~]# wget http://python.org/ftp/python/2.7.2/Python-2.7.2.tgz
  1. 解压缩以及编译
1
2
3
4
5
6
7
8
9
10
11
12
13
[root@localhost ~]# tar xvf Python-2.7.2.tgz
[root@localhost ~]# cd Python-2.7.2
[root@localhost ~]# ./configure --prefix=/usr/local/python27
[root@localhost ~]# make
[root@localhost ~]# make install
[root@localhost Python-2.7.2]# ls /usr/local/python27/ -al
总用量 24
drwxr-xr-x. 6 root root 4096 1月 15 12:42 .
drwxr-xr-x. 17 root root 4096 1月 15 12:41 ..
drwxr-xr-x. 2 root root 4096 1月 15 12:42 bin
drwxr-xr-x. 3 root root 4096 1月 15 12:42 include
drwxr-xr-x. 4 root root 4096 1月 15 12:42 lib
drwxr-xr-x. 3 root root 4096 1月 15 12:42 share
  1. 覆盖原来的python链接
    1
    2
    3
    4
    [root@localhost Python-2.7.2]# mv /usr/bin/python /usr/bin/python_old
    [root@localhost Python-2.7.2]# ln -s /usr/local/python27/bin/python /usr/bin/
    [root@localhost Python-2.7.2]# python -V
    Python 2.7.2

  此时已经可以正常使用python2.7了。
但是因为yum是使用的2.6的版本来用的,所以 还需要修改一下。

  1. 修改yum使用的Python版本

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    [root@localhost Python-2.7.2]# yum
    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.2 (default, Jan 15 2016, 12:40:26)
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-16)]
    If you cannot solve this problem yourself, please go to
    the yum faq at:
    http://yum.baseurl.org/wiki/Faq
    [root@localhost Python-2.7.2]# vim /usr/bin/yum
    #!/usr/bin/python #修改此处为2.6的位置
    [root@localhost Python-2.7.2]# vim /usr/bin/yum
    #!/usr/bin/python2.6
  2. 检查yum

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    [root@localhost Python-2.7.2]# yum
    Loaded plugins: fastestmirror, security
    You need to give some command
    Usage: yum [options] COMMAND
    List of Commands:
    check Check for problems in the rpmdb
    check-update Check for available package updates
    clean Remove cached data
    deplist List a package's dependencies
    distribution-synchronization Synchronize installed packages to the latest available versions
    downgrade downgrade a package
    erase Remove a package or packages from your system
    groupinfo Display details about a package group
    groupinstall Install the packages in a group on your system
    grouplist List available package groups
    groupremove Remove the packages in a group from your system
    help Display a helpful usage message
    history Display, or use, the transaction history
    info Display details about a package or group of packages
    install Install a package or packages on your system
    list List a package or groups of packages
    load-transaction load a saved transaction from filename
    makecache Generate the metadata cache
    provides Find what package provides the given value
    reinstall reinstall a package
    repolist Display the configured software repositories
    resolvedep Determine which package provides the given dependency
    search Search package details for the given string
    shell Run an interactive yum shell
    update Update a package or packages on your system
    update-minimal Works like update, but goes to the 'newest' package match which fixes a problem that affects your system
    updateinfo Acts on repository update information
    upgrade Update packages taking obsoletes into account
    version Display a version for the machine and/or available repos.
    Options:
    -h, --help show this help message and exit
    -t, --tolerant be tolerant of errors
    -C, --cacheonly run entirely from system cache, don't update cache
    -c [config file], --config=[config file]
    config file location
    -R [minutes], --randomwait=[minutes]
    maximum command wait time
    -d [debug level], --debuglevel=[debug level]
    debugging output level
    --showduplicates show duplicates, in repos, in list/search commands
    -e [error level], --errorlevel=[error level]
    error output level
    --rpmverbosity=[debug level name]
    debugging output level for rpm
    -q, --quiet quiet operation
    -v, --verbose verbose operation
    -y, --assumeyes answer yes for all questions
    --version show Yum version and exit
    --installroot=[path] set install root
    --enablerepo=[repo] enable one or more repositories (wildcards allowed)
    --disablerepo=[repo] disable one or more repositories (wildcards allowed)
    -x [package], --exclude=[package]
    exclude package(s) by name or glob
    --disableexcludes=[repo]
    disable exclude from main, for a repo or for everything
    --obsoletes enable obsoletes processing during updates
    --noplugins disable Yum plugins
    --nogpgcheck disable gpg signature checking
    --disableplugin=[plugin] disable plugins by name
    --enableplugin=[plugin] enable plugins by name
    --skip-broken skip packages with depsolving problems
    --color=COLOR control whether color is used
    --releasever=RELEASEVER set value of $releasever in yum config and repo files
    --setopt=SETOPTS set arbitrary config and repo options
    Plugin Options:
    --security Include security relevant packages
    --bugfixes Include bugfix relevant packages
    --cve=CVE Include packages needed to fix the given CVE
    --bz=BZ Include packages needed to fix the given BZ
    --sec-severity=SEVERITY Include security relevant packages, of this severity
    --advisory=ADVISORY Include packages needed to fix the given advisory

yum 又可以使用了