ModuleNotFoundError:没有名为“lsb_release”的模块

ModuleNotFoundError:没有名为“lsb_release”的模块

平台:Ubuntu 20.04.4 LTS

当我运行该lsb_release -a命令时,出现此错误。

# 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'

我的文件的第一行/usr/bin/lsb_release有这个。

#!/usr/bin/python3 -Es

这与本文给出的问题密切相关问题。但是那里提出的 symnlink 解决方案对我没有帮助。我尝试创建这两个符号链接。

sudo ln -s /usr/share/pyshared/lsb_release.py /usr/local/lib/python3.9/site-packages/lsb_release.py

sudo ln -s /usr/share/pyshared/lsb_release.py /usr/local/lib/python3.8/site-packages/lsb_release.py

以下是模块搜索路径(我的笔记本电脑上有 python3.9、3.8 和 2.7):

# python3
Python 3.9.5 (default, Nov 23 2021, 15:27:38) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lsb_release
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'lsb_release'
>>> exit()

# python3.8
Python 3.8.10 (default, Jun 22 2022, 20:18:18) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lsb_release
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'lsb_release'
>>> exit()

# python2.7
Python 2.7.18 (default, Jul  1 2022, 12:27:04) 
[GCC 9.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import lsb_release
>>> lsb_release.__file__
'/usr/lib/python2.7/dist-packages/lsb_release.py'
>>> exit()

答案1

对于 20.04,python3 版本应为 3.8.2-0ubuntu2。对我来说,它运行良好:

doug@s19:~/kernel/linux$ python3
Python 3.8.10 (default, Jun 22 2022, 20:18:18)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lsb_release
>>> lsb_release.__file__
'/usr/lib/python3/dist-packages/lsb_release.py'
>>> exit()
doug@s19:~/kernel/linux$

doug@s19:~/kernel/linux$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.4 LTS
Release:        20.04
Codename:       focal

相关内容