yum执行报错:File "/usr/bin/yum", line 30 except KeyboardInterrupt, e: ^

在执行yum时遇到错误,由于系统中安装了Python3,但yum脚本使用的是Python2语法。修复方法是将/usr/bin/yum文件的第一行 '#!/usr/bin/python' 修改为 '#!/usr/bin/python2',确保yum与系统Python2版本兼容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

执行yum时报错如下:

[root@server2 ~]# yum
  File "/usr/bin/yum", line 30
    except KeyboardInterrupt, e:
                            ^
SyntaxError: invalid syntax
[root@server2 ~]# 

原因是linux的python安装了python3,而yum使用python2语法编写,修改/usr/bin/yum中的首行 #!/usr/bin/python

#!/usr/bin/python2
即可

[root@server2 ~]# head -1 /usr/bin/yum
#!/usr/bin/python
[root@server2 ~]# 
[root@server2 ~]# ll /usr/bin/python*
lrwxrwxrwx. 1 root root   34 Jul 15 11:41 /usr/bin/python -> /usr/local/python3.6/bin/python3.6
lrwxrwxrwx. 1 root root   17 Jul 15 11:39 /usr/bin/python2 -> /usr/bin/python26
-rwxr-xr-x. 2 root root 8936 Jul 14  2010 /usr/bin/python26
-rwxr-xr-x. 2 root root 8936 Jul 14  2010 /usr/bin/python2.6
lrwxrwxrwx. 1 root root   34 Jul 15 11:32 /usr/bin/python3 -> /usr/local/python3.6/bin/python3.6
[root@server2 ~]# 
[root@server2 ~]# vi /usr/bin/yum
[root@server2 ~]# 
[root@server2 ~]# head -1 /usr/bin/yum
#!/usr/bin/python2
[root@server2 ~]# 
[root@server2 ~]# yum
Loaded plugins: fastestmirror
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
deplist        List a package's dependencies
distribution-synchronization Synchronize installed packages to the latest available versions
downgrade      downgrade a package
erase          Remove a package or packages from your system
groupinfo      Display details about a package group
groupinstall   Install the packages in a group on your system
grouplist      List available package groups
groupremove    Remove the packages in a group from your system
help           Display a helpful usage message
history        Display, or use, the transaction history
info           Display details about a package or group of packages
install        Install a package or packages on your system
list           List a package or groups of packages
load-transaction load a saved transaction from filename
makecache      Generate the metadata cache
provides       Find what package provides the given value
reinstall      reinstall a package
repolist       Display the configured software repositories
resolvedep     Determine which package provides the given dependency
search         Search package details for the given string
shell          Run an interactive yum shell
update         Update a package or packages on your system
upgrade        Update packages taking obsoletes into account
version        Display a version for the machine and/or available repos.


Options:
  -h, --help            show this help message and exit
  -t, --tolerant        be tolerant of errors
  -C, --cacheonly       run entirely from system cache, don't update cache
  -c [config file], --config=[config file]
                        config file location
  -R [minutes], --randomwait=[minutes]
                        maximum command wait time
  -d [debug level], --debuglevel=[debug level]
                        debugging output level
  --showduplicates      show duplicates, in repos, in list/search commands
  -e [error level], --errorlevel=[error level]
                        error output level
  --rpmverbosity=[debug level name]
                        debugging output level for rpm
  -q, --quiet           quiet operation
  -v, --verbose         verbose operation
  -y, --assumeyes       answer yes for all questions
  --assumeno            answer no for all questions
  --version             show Yum version and exit
  --installroot=[path]  set install root
  --enablerepo=[repo]   enable one or more repositories (wildcards allowed)
  --disablerepo=[repo]  disable one or more repositories (wildcards allowed)
  -x [package], --exclude=[package]
                        exclude package(s) by name or glob
  --disableexcludes=[repo]
                        disable exclude from main, for a repo or for
                        everything
  --obsoletes           enable obsoletes processing during updates
  --noplugins           disable Yum plugins
  --nogpgcheck          disable gpg signature checking
  --disableplugin=[plugin]
                        disable plugins by name
  --enableplugin=[plugin]
                        enable plugins by name
  --skip-broken         skip packages with depsolving problems
  --color=COLOR         control whether color is used
  --releasever=RELEASEVER
                        set value of $releasever in yum config and repo files
  --downloadonly        don't update, just download
  --downloaddir=DLDIR   specifies an alternate directory to store packages
  --setopt=SETOPTS      set arbitrary config and repo options

  Plugin Options:
[root@server2 ~]# 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值