centos 6.x 设置默认的 python 2.6 为 python 2.7

centos 6.x 的yum使用的是python 2.6,现在需要更新系统默认python为python 2.7

安装 python2.7

# yum install python27-python  python27-python-devel

查询 python2.7 的安装位置

# rpm -ql python27-python
/opt/rh/python27/root/usr/bin/pydoc
/opt/rh/python27/root/usr/bin/python
/opt/rh/python27/root/usr/bin/python2
/opt/rh/python27/root/usr/bin/python2.7
/opt/rh/python27/root/usr/share/doc/python27-python-2.7.13
/opt/rh/python27/root/usr/share/doc/python27-python-2.7.13/LICENSE
/opt/rh/python27/root/usr/share/doc/python27-python-2.7.13/README
/opt/rh/python27/root/usr/share/man/man1/python.1.gz
/opt/rh/python27/root/usr/share/man/man1/python2.1.gz
/opt/rh/python27/root/usr/share/man/man1/python2.7.1.gz
# rpm -ql python27-python-devel
/etc/rpm/macros.python2.python27
/opt/rh/python27/root/usr/bin/python-config
/opt/rh/python27/root/usr/bin/python2-config
/opt/rh/python27/root/usr/bin/python2.7-config

/opt/rh/python27/root/usr/lib64/libpython2.7.so
/opt/rh/python27/root/usr/lib64/pkgconfig
/opt/rh/python27/root/usr/lib64/pkgconfig/python-2.7.pc
/opt/rh/python27/root/usr/lib64/pkgconfig/python.pc
/opt/rh/python27/root/usr/lib64/pkgconfig/python2.pc
/opt/rh/python27/root/usr/lib64/python2.7/config/Setup
/opt/rh/python27/root/usr/lib64/python2.7/config/Setup.config
/opt/rh/python27/root/usr/lib64/python2.7/config/Setup.local
/opt/rh/python27/root/usr/lib64/python2.7/config/config.c
/opt/rh/python27/root/usr/lib64/python2.7/config/config.c.in
/opt/rh/python27/root/usr/lib64/python2.7/config/install-sh
/opt/rh/python27/root/usr/lib64/python2.7/config/libpython2.7.so
/opt/rh/python27/root/usr/lib64/python2.7/config/makesetup
/opt/rh/python27/root/usr/lib64/python2.7/config/python.o
/opt/rh/python27/root/usr/lib64/python2.7/distutils/command/wininst-6.0.exe
/opt/rh/python27/root/usr/lib64/python2.7/distutils/command/wininst-7.1.exe
/opt/rh/python27/root/usr/lib64/python2.7/distutils/command/wininst-8.0.exe
/opt/rh/python27/root/usr/lib64/python2.7/distutils/command/wininst-9.0-amd64.exe
/opt/rh/python27/root/usr/lib64/python2.7/distutils/command/wininst-9.0.exe

/usr/lib/rpm/redhat/brp-python-bytecompile-with-scl-python

替换系统默认的python

# which python
/usr/bin/python
# cd /usr/bin
# ls -l /usr/bin|grep -i python
-rwxr-xr-x. 1 root root      20152 May 12  2016 abrt-action-analyze-python
-rwxr-xr-x. 2 root root       9032 Aug 18  2016 python
lrwxrwxrwx. 1 root root          6 Apr 19 17:48 python2 -> python
-rwxr-xr-x. 2 root root       9032 Aug 18  2016 python2.6
-rwxr-xr-x. 1 root root       1418 Aug 18  2016 python2.6-config
lrwxrwxrwx. 1 root root         16 Apr 19 17:54 python-config -> python2.6-config

# md5sum python2.6 python
583180f2d76da4062c8c4bd4dd364d10  python2.6
583180f2d76da4062c8c4bd4dd364d10  python
# mv python python.bak

# ln -s /opt/rh/python27/root/usr/bin/python2.7 python
# ls -l /usr/bin|grep -i python
-rwxr-xr-x. 1 root root      20152 May 12  2016 abrt-action-analyze-python
lrwxrwxrwx. 1 root root         39 Apr 19 18:34 python -> /opt/rh/python27/root/usr/bin/python2.7
lrwxrwxrwx. 1 root root          6 Apr 19 17:48 python2 -> python
-rwxr-xr-x. 2 root root       9032 Aug 18  2016 python2.6
-rwxr-xr-x. 1 root root       1418 Aug 18  2016 python2.6-config
-rwxr-xr-x. 2 root root       9032 Aug 18  2016 python.bak
lrwxrwxrwx. 1 root root         16 Apr 19 17:54 python-config -> python2.6-config

修改ld

# vi /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/lib
/usr/local/lib64
/opt/rh/python27/root/usr/lib64/

# ldconfig
# python
Python 2.7.13 (default, Apr 12 2017, 06:53:51) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

修改yum使用的python 2.6

# which yum
/usr/bin/yum
# vi /usr/bin/yum
调整前 #!/usr/bin/python
调整后 #!/usr/bin/python2.6

至此,centos 6.x 上更换 python 2.6 为 2.7 完成。

原文地址:https://www.cnblogs.com/ctypyb2002/p/9793001.html