码迷,mamicode.com
首页 > 编程语言 > 详细

linux升级python到2.7版本

时间:2019-11-02 09:26:01      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:sage   can   pos   软链接   and   possible   nload   save   als   

  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
--2019-11-01 17:28:55--  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::223
Connecting to www.python.org|151.101.108.223|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 16768806 (16M) [application/octet-stream]
Saving to: “Python-2.7.10.tgz”

 4% [====>                                                                                                                          ] 670,943     6.86K/s  eta 39m 50s 
10% [============>                                                                                                                  ] 1,791,740   19.2K/s  eta 28m 3s  
34% [===========================================>                                                                                   ] 5,849,199   42.7K/s  eta 9m 22s  
66% [===================================================================================>                                           ] 11,109,885  33.2K/s  eta 3m 25s  
91% [===================================================================================================================>           ] 15,381,928  43.1K/s  eta 45s     
100%[==============================================================================================================================>] 16,768,806  53.8K/s   in 8m 54s  

2019-11-01 17:37:50 (30.7 KB/s) - “Python-2.7.10.tgz” saved [16768806/16768806]

  解压、编译:

[root@centos src]# tar -zxvf Python-2.7.10.tgz 
[root@centos src]# cd Python-2.7.10
[root@entos Python-2.7.10]# ./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... 32-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.10:
configure: error: no acceptable C compiler found in $PATH
See `config.log for more details

  好吧,编译失败,提示没有C编译器,安装gcc:

[root@centos Python-2.7.10]# yum install gcc
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
epel                                                                                                                                             | 5.3 kB     00:00     
extras                                                                                                                                           | 3.3 kB     00:00     
os                                                                                                                                               | 3.7 kB     00:00     
updates                                                                                                                                          | 3.4 kB     00:00     
Resolving Dependencies
--> Running transaction check
---> Package gcc.i686 0:4.4.7-23.el6 will be installed
--> Processing Dependency: libgomp = 4.4.7-23.el6 for package: gcc-4.4.7-23.el6.i686
--> Processing Dependency: cpp = 4.4.7-23.el6 for package: gcc-4.4.7-23.el6.i686
--> Processing Dependency: libgcc >= 4.4.7-23.el6 for package: gcc-4.4.7-23.el6.i686
--> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc-4.4.7-23.el6.i686
--> Processing Dependency: cloog-ppl >= 0.15 for package: gcc-4.4.7-23.el6.i686
--> Processing Dependency: libgomp.so.1 for package: gcc-4.4.7-23.el6.i686
--> Running transaction check
---> Package cloog-ppl.i686 0:0.15.7-1.2.el6 will be installed
--> Processing Dependency: libppl_c.so.2 for package: cloog-ppl-0.15.7-1.2.el6.i686
--> Processing Dependency: libppl.so.7 for package: cloog-ppl-0.15.7-1.2.el6.i686
---> Package cpp.i686 0:4.4.7-23.el6 will be installed
--> Processing Dependency: libmpfr.so.1 for package: cpp-4.4.7-23.el6.i686
---> Package glibc-devel.i686 0:2.12-1.212.el6_10.3 will be installed
--> Processing Dependency: glibc-headers = 2.12-1.212.el6_10.3 for package: glibc-devel-2.12-1.212.el6_10.3.i686
--> Processing Dependency: glibc = 2.12-1.212.el6_10.3 for package: glibc-devel-2.12-1.212.el6_10.3.i686
--> Processing Dependency: glibc-headers for package: glibc-devel-2.12-1.212.el6_10.3.i686
---> Package libgcc.i686 0:4.4.7-18.el6 will be updated
---> Package libgcc.i686 0:4.4.7-23.el6 will be an update
---> Package libgomp.i686 0:4.4.7-23.el6 will be installed
--> Running transaction check
---> Package glibc.i686 0: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 0:2.12-1.212.el6_10.3 will be an update
---> Package glibc-headers.i686 0:2.12-1.212.el6_10.3 will be installed
--> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers-2.12-1.212.el6_10.3.i686
--> Processing Dependency: kernel-headers for package: glibc-headers-2.12-1.212.el6_10.3.i686
---> Package mpfr.i686 0:2.4.1-6.el6 will be installed
---> Package ppl.i686 0:0.10.2-11.el6 will be installed
--> Running transaction check
---> Package glibc-common.i686 0:2.12-1.209.el6 will be updated
---> Package glibc-common.i686 0:2.12-1.212.el6_10.3 will be an update
---> Package kernel-headers.i686 0:2.6.32-754.23.1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================
 Package                                    Arch                             Version                                          Repository                           Size
========================================================================================================================================================================
Installing:
 gcc                                        i686                             4.4.7-23.el6                                     os                                  8.2 M
Installing for dependencies:
 cloog-ppl                                  i686                             0.15.7-1.2.el6                                   os                                   93 k
 cpp                                        i686                             4.4.7-23.el6                                     os                                  3.4 M
 glibc-devel                                i686                             2.12-1.212.el6_10.3                              updates                             991 k
 glibc-headers                              i686                             2.12-1.212.el6_10.3                              updates                             628 k
 kernel-headers                             i686                             2.6.32-754.23.1.el6                              updates                             4.6 M
 libgomp                                    i686                             4.4.7-23.el6                                     os                                  137 k
 mpfr                                       i686                             2.4.1-6.el6                                      os                                  153 k
 ppl                                        i686                             0.10.2-11.el6                                    os                                  1.3 M
Updating for dependencies:
 glibc                                      i686                             2.12-1.212.el6_10.3                              updates                             4.4 M
 glibc-common                               i686                             2.12-1.212.el6_10.3                              updates                              14 M
 libgcc                                     i686                             4.4.7-23.el6                                     os                                  115 k

Transaction Summary
========================================================================================================================================================================
Install       9 Package(s)
Upgrade       3 Package(s)

Total download size: 38 M
Is this ok [y/N]: y
Downloading Packages:
(1/12): cloog-ppl-0.15.7-1.2.el6.i686.rpm                                                                                                        |  93 kB     00:00     
(2/12): cpp-4.4.7-23.el6.i686.rpm                                                                                                                | 3.4 MB     00:00     
(3/12): gcc-4.4.7-23.el6.i686.rpm                                                                                                                | 8.2 MB     00:00     
(4/12): glibc-2.12-1.212.el6_10.3.i686.rpm                                                                                                       | 4.4 MB     00:00     
(5/12): glibc-common-2.12-1.212.el6_10.3.i686.rpm                                                                                                |  14 MB     00:00     
(6/12): glibc-devel-2.12-1.212.el6_10.3.i686.rpm                                                                                                 | 991 kB     00:00     
(7/12): glibc-headers-2.12-1.212.el6_10.3.i686.rpm                                                                                               | 628 kB     00:00     
(8/12): kernel-headers-2.6.32-754.23.1.el6.i686.rpm                                                                                              | 4.6 MB     00:00     
(9/12): libgcc-4.4.7-23.el6.i686.rpm                                                                                                             | 115 kB     00:00     
(10/12): libgomp-4.4.7-23.el6.i686.rpm                                                                                                           | 137 kB     00:00     
(11/12): mpfr-2.4.1-6.el6.i686.rpm                                                                                                               | 153 kB     00:00     
(12/12): ppl-0.10.2-11.el6.i686.rpm                                                                                                              | 1.3 MB     00:00     
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                    43 MB/s |  38 MB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : kernel-headers-2.6.32-754.23.1.el6.i686                                                                                                             1/15 
  Updating   : libgcc-4.4.7-23.el6.i686                                                                                                                            2/15 
  Updating   : glibc-common-2.12-1.212.el6_10.3.i686                                                                                                               3/15 
  Updating   : glibc-2.12-1.212.el6_10.3.i686                                                                                                                      4/15 
  Installing : glibc-headers-2.12-1.212.el6_10.3.i686                                                                                                              5/15 
  Installing : glibc-devel-2.12-1.212.el6_10.3.i686                                                                                                                6/15 
  Installing : libgomp-4.4.7-23.el6.i686                                                                                                                           7/15 
  Installing : mpfr-2.4.1-6.el6.i686                                                                                                                               8/15 
  Installing : cpp-4.4.7-23.el6.i686                                                                                                                               9/15 
  Installing : ppl-0.10.2-11.el6.i686                                                                                                                             10/15 
  Installing : cloog-ppl-0.15.7-1.2.el6.i686                                                                                                                      11/15 
  Installing : gcc-4.4.7-23.el6.i686                                                                                                                              12/15 
  Cleanup    : glibc-common-2.12-1.209.el6.i686                                                                                                                   13/15 
  Cleanup    : glibc-2.12-1.209.el6.i686                                                                                                                          14/15 
  Cleanup    : libgcc-4.4.7-18.el6.i686                                                                                                                           15/15 
  Verifying  : kernel-headers-2.6.32-754.23.1.el6.i686                                                                                                             1/15 
  Verifying  : libgcc-4.4.7-23.el6.i686                                                                                                                            2/15 
  Verifying  : cpp-4.4.7-23.el6.i686                                                                                                                               3/15 
  Verifying  : libgomp-4.4.7-23.el6.i686                                                                                                                           4/15 
  Verifying  : glibc-devel-2.12-1.212.el6_10.3.i686                                                                                                                5/15 
  Verifying  : glibc-2.12-1.212.el6_10.3.i686                                                                                                                      6/15 
  Verifying  : mpfr-2.4.1-6.el6.i686                                                                                                                               7/15 
  Verifying  : glibc-headers-2.12-1.212.el6_10.3.i686                                                                                                              8/15 
  Verifying  : ppl-0.10.2-11.el6.i686                                                                                                                              9/15 
  Verifying  : glibc-common-2.12-1.212.el6_10.3.i686                                                                                                              10/15 
  Verifying  : gcc-4.4.7-23.el6.i686                                                                                                                              11/15 
  Verifying  : cloog-ppl-0.15.7-1.2.el6.i686                                                                                                                      12/15 
  Verifying  : glibc-common-2.12-1.209.el6.i686                                                                                                                   13/15 
  Verifying  : libgcc-4.4.7-18.el6.i686                                                                                                                           14/15 
  Verifying  : glibc-2.12-1.209.el6.i686                                                                                                                          15/15 

Installed:
  gcc.i686 0:4.4.7-23.el6                                                                                                                                               

Dependency Installed:
  cloog-ppl.i686 0:0.15.7-1.2.el6               cpp.i686 0:4.4.7-23.el6         glibc-devel.i686 0:2.12-1.212.el6_10.3     glibc-headers.i686 0:2.12-1.212.el6_10.3    
  kernel-headers.i686 0:2.6.32-754.23.1.el6     libgomp.i686 0:4.4.7-23.el6     mpfr.i686 0:2.4.1-6.el6                    ppl.i686 0:0.10.2-11.el6                    

Dependency Updated:
  glibc.i686 0:2.12-1.212.el6_10.3                       glibc-common.i686 0:2.12-1.212.el6_10.3                       libgcc.i686 0:4.4.7-23.el6                      

Complete!

  再次编译通过了,执行安装:

[root@centos Python-2.7.10]# make && make install

  升级python,通过软链接,将python由指向2.6.6改为2.7.0

[root@centos bin]# ls python* -l
-rwxr-xr-x  2 root root 6100 Aug 18  2016 python
lrwxrwxrwx. 1 root root    6 Dec 13  2017 python2 -> python
-rwxr-xr-x  2 root root 6100 Aug 18  2016 python2.6
[root@centos bin]# unlink python
[root@centos bin]# unlink python2
[root@centos bin]# ls python* -l
-rwxr-xr-x 1 root root 6100 Aug 18  2016 python2.6
[root@centos bin]# cp /usr/local/python27/bin/python2.7 /usr/bin/python2.7
[root@centos bin]# ls python* -l
-rwxr-xr-x 1 root root 6100 Aug 18  2016 python2.6
-rwxr-xr-x 1 root root 7776 Nov  2 00:15 python2.7
[root@centos bin]# ln -s /usr/bin/python2.7 python
[root@centos bin]# ln -s python python2
[root@centos bin]# ls python* -l
lrwxrwxrwx 1 root root   18 Nov  2 00:16 python -> /usr/bin/python2.7
lrwxrwxrwx 1 root root    6 Nov  2 00:16 python2 -> python
-rwxr-xr-x 1 root root 6100 Aug 18  2016 python2.6
-rwxr-xr-x 1 root root 7776 Nov  2 00:15 python2.7
[root@centos bin]# python -V
python: error while loading shared libraries: libpython2.7.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.

Its possible that the above module doesnt match the
current version of Python, which is:
2.7.10 (default, Nov  1 2019, 17:58:54) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-23)]

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

  打完收工。

 

linux升级python到2.7版本

标签:sage   can   pos   软链接   and   possible   nload   save   als   

原文地址:https://www.cnblogs.com/wuxun1997/p/11778505.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!