linux的python安装包默认版本是2.6.6,yum程序默认也是依赖这个版本的python包的,但是其他一些程序如nodejs,却要的是2.7版本,因此必须要考虑升级后与yum的兼容问题。两步走,先升级python,再兼容yum:
下载python的2.7版本:
[root@centos ~]# cd /usr/local/src
[root@centos src]# wget https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz
---- ::-- https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz
Resolving www.python.org... 151.101.108.223, 2a04:4e42:a::
Connecting to www.python.org|151.101.108.223|:... connected.
HTTP request sent, awaiting response... OK
Length: (16M) [application/octet-stream]
Saving to: “Python-2.7..tgz” % [====> ] , .86K/s eta 39m 50s
% [============> ] ,, .2K/s eta 28m 3s
% [===========================================> ] ,, .7K/s eta 9m 22s
% [===================================================================================> ] ,, .2K/s eta 3m 25s
% [===================================================================================================================> ] ,, .1K/s eta 45s
%[==============================================================================================================================>] ,, .8K/s in 8m 54s -- :: (30.7 KB/s) - “Python-2.7..tgz” saved [/]
解压、编译:
[root@centos src]# tar -zxvf Python-2.7..tgz
[root@centos src]# cd Python-2.7.
[root@entos Python-2.7.]# ./configure --enable-shared --enable-loadable-sqlite-extensions \
> --prefix=/usr/local/python27 \
> --with-zlib \
> --with-ssl
configure: WARNING: unrecognized options: --enable-loadable-sqlite-extensions, --with-zlib, --with-ssl
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for --enable-universalsdk... no
checking for --with-universal-archs... -bit
checking MACHDEP... linux2
checking EXTRAPLATDIR...
checking for --without-gcc... no
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/local/src/Python-2.7.':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
好吧,编译失败,提示没有C编译器,安装gcc:
[root@centos Python-2.7.]# yum install gcc
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
epel | 5.3 kB :
extras | 3.3 kB :
os | 3.7 kB :
updates | 3.4 kB :
Resolving Dependencies
--> Running transaction check
---> Package gcc.i686 :4.4.-.el6 will be installed
--> Processing Dependency: libgomp = 4.4.-.el6 for package: gcc-4.4.-.el6.i686
--> Processing Dependency: cpp = 4.4.-.el6 for package: gcc-4.4.-.el6.i686
--> Processing Dependency: libgcc >= 4.4.-.el6 for package: gcc-4.4.-.el6.i686
--> Processing Dependency: glibc-devel >= 2.2.- for package: gcc-4.4.-.el6.i686
--> Processing Dependency: cloog-ppl >= 0.15 for package: gcc-4.4.-.el6.i686
--> Processing Dependency: libgomp.so. for package: gcc-4.4.-.el6.i686
--> Running transaction check
---> Package cloog-ppl.i686 :0.15.-1.2.el6 will be installed
--> Processing Dependency: libppl_c.so. for package: cloog-ppl-0.15.-1.2.el6.i686
--> Processing Dependency: libppl.so. for package: cloog-ppl-0.15.-1.2.el6.i686
---> Package cpp.i686 :4.4.-.el6 will be installed
--> Processing Dependency: libmpfr.so. for package: cpp-4.4.-.el6.i686
---> Package glibc-devel.i686 :2.12-1.212.el6_10. will be installed
--> Processing Dependency: glibc-headers = 2.12-1.212.el6_10. for package: glibc-devel-2.12-1.212.el6_10..i686
--> Processing Dependency: glibc = 2.12-1.212.el6_10. for package: glibc-devel-2.12-1.212.el6_10..i686
--> Processing Dependency: glibc-headers for package: glibc-devel-2.12-1.212.el6_10..i686
---> Package libgcc.i686 :4.4.-.el6 will be updated
---> Package libgcc.i686 :4.4.-.el6 will be an update
---> Package libgomp.i686 :4.4.-.el6 will be installed
--> Running transaction check
---> Package glibc.i686 :2.12-1.209.el6 will be updated
--> Processing Dependency: glibc = 2.12-1.209.el6 for package: glibc-common-2.12-1.209.el6.i686
---> Package glibc.i686 :2.12-1.212.el6_10. will be an update
---> Package glibc-headers.i686 :2.12-1.212.el6_10. will be installed
--> Processing Dependency: kernel-headers >= 2.2. for package: glibc-headers-2.12-1.212.el6_10..i686
--> Processing Dependency: kernel-headers for package: glibc-headers-2.12-1.212.el6_10..i686
---> Package mpfr.i686 :2.4.-.el6 will be installed
---> Package ppl.i686 :0.10.-.el6 will be installed
--> Running transaction check
---> Package glibc-common.i686 :2.12-1.209.el6 will be updated
---> Package glibc-common.i686 :2.12-1.212.el6_10. will be an update
---> Package kernel-headers.i686 :2.6.-754.23..el6 will be installed
--> Finished Dependency Resolution Dependencies Resolved ========================================================================================================================================================================
Package Arch Version Repository Size
========================================================================================================================================================================
Installing:
gcc i686 4.4.-.el6 os 8.2 M
Installing for dependencies:
cloog-ppl i686 0.15.-1.2.el6 os k
cpp i686 4.4.-.el6 os 3.4 M
glibc-devel i686 2.12-1.212.el6_10. updates k
glibc-headers i686 2.12-1.212.el6_10. updates k
kernel-headers i686 2.6.-754.23..el6 updates 4.6 M
libgomp i686 4.4.-.el6 os k
mpfr i686 2.4.-.el6 os k
ppl i686 0.10.-.el6 os 1.3 M
Updating for dependencies:
glibc i686 2.12-1.212.el6_10. updates 4.4 M
glibc-common i686 2.12-1.212.el6_10. updates M
libgcc i686 4.4.-.el6 os k Transaction Summary
========================================================================================================================================================================
Install Package(s)
Upgrade Package(s) Total download size: M
Is this ok [y/N]: y
Downloading Packages:
(/): cloog-ppl-0.15.-1.2.el6.i686.rpm | kB :
(/): cpp-4.4.-.el6.i686.rpm | 3.4 MB :
(/): gcc-4.4.-.el6.i686.rpm | 8.2 MB :
(/): glibc-2.12-1.212.el6_10..i686.rpm | 4.4 MB :
(/): glibc-common-2.12-1.212.el6_10..i686.rpm | MB :
(/): glibc-devel-2.12-1.212.el6_10..i686.rpm | kB :
(/): glibc-headers-2.12-1.212.el6_10..i686.rpm | kB :
(/): kernel-headers-2.6.-754.23..el6.i686.rpm | 4.6 MB :
(/): libgcc-4.4.-.el6.i686.rpm | kB :
(/): libgomp-4.4.-.el6.i686.rpm | kB :
(/): mpfr-2.4.-.el6.i686.rpm | kB :
(/): ppl-0.10.-.el6.i686.rpm | 1.3 MB :
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total MB/s | MB :
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : kernel-headers-2.6.-754.23..el6.i686 /
Updating : libgcc-4.4.-.el6.i686 /
Updating : glibc-common-2.12-1.212.el6_10..i686 /
Updating : glibc-2.12-1.212.el6_10..i686 /
Installing : glibc-headers-2.12-1.212.el6_10..i686 /
Installing : glibc-devel-2.12-1.212.el6_10..i686 /
Installing : libgomp-4.4.-.el6.i686 /
Installing : mpfr-2.4.-.el6.i686 /
Installing : cpp-4.4.-.el6.i686 /
Installing : ppl-0.10.-.el6.i686 /
Installing : cloog-ppl-0.15.-1.2.el6.i686 /
Installing : gcc-4.4.-.el6.i686 /
Cleanup : glibc-common-2.12-1.209.el6.i686 /
Cleanup : glibc-2.12-1.209.el6.i686 /
Cleanup : libgcc-4.4.-.el6.i686 /
Verifying : kernel-headers-2.6.-754.23..el6.i686 /
Verifying : libgcc-4.4.-.el6.i686 /
Verifying : cpp-4.4.-.el6.i686 /
Verifying : libgomp-4.4.-.el6.i686 /
Verifying : glibc-devel-2.12-1.212.el6_10..i686 /
Verifying : glibc-2.12-1.212.el6_10..i686 /
Verifying : mpfr-2.4.-.el6.i686 /
Verifying : glibc-headers-2.12-1.212.el6_10..i686 /
Verifying : ppl-0.10.-.el6.i686 /
Verifying : glibc-common-2.12-1.212.el6_10..i686 /
Verifying : gcc-4.4.-.el6.i686 /
Verifying : cloog-ppl-0.15.-1.2.el6.i686 /
Verifying : glibc-common-2.12-1.209.el6.i686 /
Verifying : libgcc-4.4.-.el6.i686 /
Verifying : glibc-2.12-1.209.el6.i686 / Installed:
gcc.i686 :4.4.-.el6 Dependency Installed:
cloog-ppl.i686 :0.15.-1.2.el6 cpp.i686 :4.4.-.el6 glibc-devel.i686 :2.12-1.212.el6_10. glibc-headers.i686 :2.12-1.212.el6_10.
kernel-headers.i686 :2.6.-754.23..el6 libgomp.i686 :4.4.-.el6 mpfr.i686 :2.4.-.el6 ppl.i686 :0.10.-.el6 Dependency Updated:
glibc.i686 :2.12-1.212.el6_10. glibc-common.i686 :2.12-1.212.el6_10. libgcc.i686 :4.4.-.el6 Complete!
再次编译通过了,执行安装:
[root@centos Python-2.7.]# make && make install
升级python,通过软链接,将python由指向2.6.6改为2.7.0
[root@centos bin]# ls python* -l
-rwxr-xr-x root root Aug python
lrwxrwxrwx. root root Dec python2 -> python
-rwxr-xr-x root root Aug python2.
[root@centos bin]# unlink python
[root@centos bin]# unlink python2
[root@centos bin]# ls python* -l
-rwxr-xr-x root root Aug python2.
[root@centos bin]# cp /usr/local/python27/bin/python2. /usr/bin/python2.
[root@centos bin]# ls python* -l
-rwxr-xr-x root root Aug python2.
-rwxr-xr-x root root Nov : python2.
[root@centos bin]# ln -s /usr/bin/python2. python
[root@centos bin]# ln -s python python2
[root@centos bin]# ls python* -l
lrwxrwxrwx root root Nov : python -> /usr/bin/python2.
lrwxrwxrwx root root Nov : python2 -> python
-rwxr-xr-x root root Aug python2.
-rwxr-xr-x root root Nov : python2.
[root@centos bin]# python -V
python: error while loading shared libraries: libpython2..so.1.0: cannot open shared object file: No such file or directory
看版本又冒出来一个问题,找不到一个库文件,需编辑下配置文件/etc/ld.so.conf,指定一下库路径:
保存好后让它生效,现在ok了:
[root@centos bin]# ldconfig
[root@centos bin]# python -V
Python 2.7.10
现在搞第二个问题:yum的兼容,执行yum会提示导入python包出错:
[root@centos bin]# 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. (default, Nov , ::)
[GCC 4.4. (Red Hat 4.4.-)] If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq
通过vi编辑/usr/bin/yum,把第一行最后加上2.6即可
再试试:
[root@centos bin]# 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
打完收工。