error:安裝pip執行`yum -y install epel-release`報錯`SyntaxError: invalid syntax`

在Centos7中安裝pip時,安裝執行命令如下:

yum -y install epel-release               
yum -y install python-pip                
pip --version  查看pip版本

在執行第一步命令時,報錯:

[root@VM_0_6_centos bin]# yum -y install epel-release
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-12 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================
 Package                        Arch                     Version                Repository              Size
=============================================================================================================
Installing:
 epel-release                   noarch                   7-12                   epel                    15 k

Transaction Summary
=============================================================================================================
Install  1 Package

Total download size: 15 k
Installed size: 24 k
Downloading packages:
  File "/usr/libexec/urlgrabber-ext-down", line 28
    except OSError, e:
                  ^
SyntaxError: invalid syntax


Exiting on user cancel

這裏應該時我們在Centos7中安裝python3時,把軟連接的python-->python2.7的命令修改爲python --> python3,導致文件"/usr/libexec/urlgrabber-ext-down"中的python版本出現錯誤,這裏只需要將該文本的第一行的#! /usr/bin/python更新爲#! /usr/bin/python2.7即可。

[root@VM_0_6_centos libexec]# vi urlgrabber-ext-down 

r/libexec/urlgrabber-ext-down"! /usr/bin/python2.7
#  A very simple external downloader
#  Copyright 2011-2012 Zdenek Pavlas

#   This library is free software; you can redistribute it and/or
#   modify it under the terms of the GNU Lesser General Public
#   License as published by the Free Software Foundation; either
#   version 2.1 of the License, or (at your option) any later version.
#
#   This library is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#   Lesser General Public License for more details.
#
#   You should have received a copy of the GNU Lesser General Public
#   License along with this library; if not, write to the
#      Free Software Foundation, Inc.,
#      59 Temple Place, Suite 330,
#      Boston, MA  02111-1307  USA

import time, os, errno, sys
from urlgrabber.grabber import \
    _readlines, URLGrabberOptions, _loads, \
    PyCurlFileObject, URLGrabError

def write(fmt, *arg):
    try: os.write(1, fmt % arg)
    except OSError, e:
        if e.args[0] != errno.EPIPE: raise
        sys.exit(1)

修改完成後,保存退出。然後重複執行以下步驟便可以正常安裝了。

yum -y install epel-release               
yum -y install python-pip  
pip --version  查看pip版本  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章