背景
公司爬虫需要使用python3.6.8版本,因此升级centos的python2到python3.6.8。但是当使用yum安装包时 ,出现如下异常:
sh
[root@localhost bin]# yum install npm -y
Loaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* centos-sclo-rh: mirrors.ustc.edu.cn
* epel: mirror.01link.hk
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
File "/usr/libexec/urlgrabber-ext-down", line 28
except OSError, e:
^
SyntaxError: invalid syntax
File "/usr/libexec/urlgrabber-ext-down", line 28
except OSError, e:
^
SyntaxError: invalid syntax
File "/usr/libexec/urlgrabber-ext-down", line 28
except OSError, e:
^
SyntaxError: invalid syntax
File "/usr/libexec/urlgrabber-ext-down", line 28
except OSError, e:
^
SyntaxError: invalid syntax
File "/usr/libexec/urlgrabber-ext-down", line 28
except OSError, e:
^
SyntaxError: invalid syntax
在网上搜索了一圈结果都是相互copy,因此,我就整合了各种处理方案进行解决。
解决
- 1.查看当前系统版本
sh
python -V
- 2.查看yum使用的python版本并修改yum的python版本到2.7
sh
cat /usr/bin/yum
vim /usr/bin/yum
- 3.使用yum下载
sh
yum install npm -y
仍然提示如下异常:
根据异常可以推断出应该也是python版本问题,因此,找到异常文件并修改python版本
sh
cat /usr/libexec/urlgrabber-ext-down
vim /usr/libexec/urlgrabber-ext-down
修改:
- 4.重新使用yum命令安装
到此,安装成功