在Python2和Python并存的环境下,有一些使用Python2的命令稍不注意就会出现问题,例如-iotop,我也是排查es占用io过高时才发现的问题。
[root@elk-server bin]# iotop
No module named 'iotop'
To run an uninstalled copy of iotop,
launch iotop.py in the top directory
通过排查发现是Python环境导致的问题,开头是-----#!/usr/bin/python,我的Python指向已经不是Python2版本了。
#!/usr/bin/python
# iotop: Display I/O usage of processes in a top like UI
# Copyright (c) 2007, 2008 Guillaume Chazarain <guichaz@gmail.com>, GPLv2
# See iotop --help for some help
from __future__ import print_function
import sys
try:
from iotop.ui import main
except ImportError as e:
print(e)
print('To run an uninstalled copy of iotop,')
print('launch iotop.py in the top directory')
else:
try:
main()
except KeyboardInterrupt:
pass
sys.exit(0)

解决:指定之前的python版本即可
vim /usr/sbin/iotop
#!/usr/bin/python2
解决iotop在Python3环境下的兼容性问题

本文详细介绍了在Python2和Python3共存的环境中,使用iotop命令遇到的兼容性问题及解决方案。由于iotop默认使用Python解释器运行,当系统默认Python版本为Python3时,可能会因模块不兼容而失败。文章提供了修改iotop脚本头部,指定使用Python2的具体步骤。
723





