正常使用的Ubuntu 16.04,执行一些基本命令,比如ufw,lsb_release,突然出现失败。
root# lsb_release -a
Traceback (most recent call last):
File "/usr/bin/lsb_release", line 25, in <module>
import lsb_release
ModuleNotFoundError: No module named 'lsb_release'
在网络搜索“No module named 'lsb_release'”,发现有论坛帖子描述安装新的Python后,也出现lsb_release不能使用的情况。
检查电脑的Python版本,发现已经是3.7。后来沟通,发现有同事根据文章ubuntu安装python3.7从源代码安装了Python 3.7。
root:/usr/bin# ls -l | grep python
lrwxrwxrwx 1 root root 26 Aug 16 2019 dh_pypy -> ../share/dh-python/dh_pypy
-rwxr-xr-x 1 root root 1056 Nov 24 2017 dh_python2
lrwxrwxrwx 1 root root 29 Aug 16 2019 dh_python3 -> ../share/dh-python/dh_python3
lrwxrwxrwx 1 root root 23 Oct 9 01:01 pdb2.7 -> ../lib/python2.7/pdb.py
lrwxrwxrwx 1 root root 23 Oct 8 22:41 pdb3.5 -> ../lib/python3.5/pdb.py
lrwxrwxrwx 1 root root 29 Mar 19 13:46 pip3 -> /usr/local/python3/bin/pip3.7
lrwxrwxrwx 1 root root 31 Jul 30 2019 py3versions -> ../share/python3/py3versions.py
lrwxrwxrwx 1 root root 26 Aug 16 2019 pybuild -> ../share/dh-python/pybuild
lrwxrwxrwx 1 root root 9 Mar 30 16:04 python -> python2.7
lrwxrwxrwx 1 root root 9 Jul 30 2019 python2 -> python2.7
-rwxr-xr-x 1 root root 3492656 Oct 9 01:01 python2.7
lrwxrwxrwx 1 root root 33 Oct 9 01:01 python2.7-config -> x86_64-linux-gnu-python2.7-config
lrwxrwxrwx 1 root root 16 Nov 24 2017 python2-config -> python2.7-config
lrwxrwxrwx 1 root root 32 Mar 19 13:45 python3 -> /usr/local/python3/bin/python3.7
-rwxr-xr-x 2 root root 4452016 Oct 8 22:41 python3.5
-rwxr-xr-x 2 root root 4452016 Oct 8 22:41 python3.5m
lrwxrwxrwx 1 root root 10 Jul 30 2019 python3m -> python3.5m
lrwxrwxrwx 1 root root 16 Nov 24 2017 python-config -> python2.7-config
lrwxrwxrwx 1 root root 29 Jul 30 2019 pyversions -> ../share/python/pyversions.py
-rwxr-xr-x 1 root root 2909 Oct 9 00:59 x86_64-linux-gnu-python2.7-config
lrwxrwxrwx 1 root root 33 Nov 24 2017 x86_64-linux-gnu-python-config -> x86_64-linux-gnu python2.7-config
于是删除python 3.7的连接,恢复python 3.5的连接。再测试lsb_release和ufw命令,都恢复正常。
root:/usr/bin# rm python3
root:/usr/bin# ln -s python3.5 python3
root:/usr/bin# rm pip3
root:/usr/bin# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.6 LTS
Release: 16.04
Codename: xenial
root:/usr/bin# ufw disable
Firewall stopped and disabled on system startup