在我的计算机上,所有依赖该lsb_release
命令的东西都无法运行。
例子:
pip install numpy
引发子进程.CalledProcessError(代码、cmd、stdout、stderr)子进程.CalledProcessError:命令‘lsb_release -a’返回非零退出状态 1
事实上,lsb_release -a
会产生错误
File "/usr/bin/lsb_release", line 95, in <module>
main()
File "/usr/bin/lsb_release", line 59, in main
distinfo = lsb_release.get_distro_information()
File "/usr/lib/python3/dist-packages/lsb_release.py", line 383, in get_distro_information
distinfo = guess_debian_release()
File "/usr/lib/python3/dist-packages/lsb_release.py", line 281, in guess_debian_release
get_distro_info(distinfo['ID'])
File "/usr/lib/python3/dist-packages/lsb_release.py", line 41, in get_distro_info
RELEASES_ORDER.sort(key=lambda n: float(n[0]))
File "/usr/lib/python3/dist-packages/lsb_release.py", line 41, in <lambda>
RELEASES_ORDER.sort(key=lambda n: float(n[0]))
ValueError: could not convert string to float: '8.04 LTS'
我知道在python中'8.04 LTS'
不能转换为float
,但是为什么会发生这种情况。
我尝试重新安装两者lsb_release
,python-pip
但问题依然没有得到解决。
我在线Ubuntu 16.04 LTS
。有什么帮助吗?
答案1
我的一台虚拟机出现了同样的错误,其他两台虚拟机和虚拟机管理程序都正常。同一版本(16.04.3),不知道是什么原因造成的。这是一个已知错误。
我松了一口气这里
修改文件/usr/share/pyshared/lsb_release.py
第 41 行:
RELEASES_ORDER.sort(key=lambda n: float(n[0]))
到:
RELEASES_ORDER.sort(key=lambda n: float(n[0].split()[0]))
帮我解决了问题。Ubuntu bug launchpad 上的 SHIINA Hideaki (shiina) 功不可没。我只是在这里重新发布它。
答案2
当我运行时出现问题lsb_release -a
Traceback (most recent call last):
File "/usr/bin/lsb_release", line 95, in <module>
main()
File "/usr/bin/lsb_release", line 59, in main
distinfo = lsb_release.get_distro_information()
File "/usr/lib/python3/dist-packages/lsb_release.py", line 398, in get_distro_information
distinfo = guess_debian_release()
File "/usr/lib/python3/dist-packages/lsb_release.py", line 288, in guess_debian_release
get_distro_info(distinfo['ID'])
File "/usr/lib/python3/dist-packages/lsb_release.py", line 48, in get_distro_info
RELEASES_ORDER.sort(key=lambda n: float(n[0]))
File "/usr/lib/python3/dist-packages/lsb_release.py", line 48, in <lambda>
RELEASES_ORDER.sort(key=lambda n: float(n[0]))
ValueError: could not convert string to float: '6.06 LTS'
让我们检查一下文件/usr/lib/python3/dist-packages/lsb_release.py
try:
csvfile = open('/usr/share/distro-info/%s.csv' % origin.lower())
except FileNotFoundException:
# Unknown distro, fallback to Debian
csvfile = open('/usr/share/distro-info/debian.csv')
....
RELEASES_ORDER = list(RELEASE_CODENAME_LOOKUP.items())
RELEASES_ORDER.sort(key=lambda n: float(n[0]))
它加载文件/usr/share/distro-info/%s.csv
,并将第一项转换为浮点类型,该类型可能包含像“LTS”这样的字符串。因此,我修改了第 48 行,/usr/lib/python3/dist-packages/lsb_release.py
如下所示,它对我有用。
RELEASES_ORDER.sort(key=lambda n: (n[0]))