正常使用的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
