当前位置: 代码迷 >> 综合 >> lsb_release conda failed ValueError: could not convert string to float: 16.04 LTS
  详细解决方案

lsb_release conda failed ValueError: could not convert string to float: 16.04 LTS

热度:20   发布时间:2023-12-15 16:51:14.0

使用lsb_release 查看ubuntu版本号时报错:ValueError: could not convert string to float: '8.04 LTS’

$ sudo 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 maindistinfo = lsb_release.get_distro_information()File "/usr/lib/python3/dist-packages/lsb_release.py", line 398, idistinfo = guess_debian_release()File "/usr/lib/python3/dist-packages/lsb_release.py", line 288, iget_distro_info(distinfo['ID'])File "/usr/lib/python3/dist-packages/lsb_release.py", line 48, inRELEASES_ORDER.sort(key=lambda n: float(n[0]))File "/usr/lib/python3/dist-packages/lsb_release.py", line 48, inRELEASES_ORDER.sort(key=lambda n: float(n[0]))
ValueError: could not convert string to float: '8.04 LTS'

使用conda时也报错:Collecting package metadata (current_repodata.json): failed

$ conda install nb_conda_kernels
Collecting package metadata (current_repodata.json): failed# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<Traceback (most recent call last):File "/home/user1/miniconda3/lib/python3.7/site-packages/conda/gateways/connection/session.py", line 52, in __call__return cls._thread_local.sessionAttributeError: '_thread._local' object has no attribute 'session'During handling of the above exception, another exception occurred:Traceback (most recent call last):File "/home/user1/miniconda3/lib/python3.7/site-packages/conda/exceptions.py", line 1079, in __call__return func(*args, **kwargs)File "/home/user1/miniconda3/lib/python3.7/site-packages/conda/cli/main.py", line 84, in _mainexit_code = do_call(args, p)File "/home/user1/miniconda3/lib/python3.7/site-packages/conda/cli/conda_argparse.py", line 82, in do_callreturn getattr(module, func_name)(args, parser)File "/home/user1/miniconda3/lib/python3.7/site-packages/conda/cli/main_install.py", line 20, in executeinstall(args, parser, 'install')File "/home/user1/miniconda3/lib/python3.7/site-packages/conda/cli/install.py", line 265, in installshould_retry_solve=(_should_retry_unfrozen or repodata_fn != repodata_fns[-1]),File "/home/user1/miniconda3/lib/python3.7/site-packages/conda/core/solve.py", line 117, in solve_for_transactionshould_retry_solve)File "/home/user1/miniconda3/lib/python3.7/site-packages/conda/core/solve.py", line 158, in solve_for_diffforce_remove, should_retry_solve)File "/home/user1/miniconda3/lib/python3.7/site-packages/conda/core/solve.py", line 262, in solve_final_statessc = self._collect_all_metadata(ssc)File "/home/user1/miniconda3/lib/python3.7/site-packages/conda/common/io.py", line 88, in decoratedreturn f(*args, **kwds)File "/home/user1/miniconda3/lib/python3.7/site-packages/conda/core/solve.py", line 415, in _collect_all_metadataindex, r = self._prepare(prepared_specs)File "/home/user1/miniconda3/lib/python3.7/site-packages/conda/core/solve.py", line 1011, in _prepareself.subdirs, prepared_specs, self._repodata_fn)File "/home/user1/miniconda3/lib/python3.7/site-packages/conda/core/index.py", line 228, in get_reduced_indexrepodata_fn=repodata_fn)File "/home/user1/miniconda3/lib/python3.7/site-packages/conda/core/subdir_data.py", line 105, in query_allresult = tuple(concat(executor.map(subdir_query, channel_urls)))File "/home/user1/miniconda3/lib/python3.7/concurrent/futures/_base.py", line 598, in result_iteratoryield fs.pop().result()File "/home/user1/miniconda3/lib/python3.7/concurrent/futures/_base.py", line 435, in resultreturn self.__get_result()File "/home/user1/miniconda3/lib/python3.7/concurrent/futures/_base.py", line 384, in __get_resultraise self._exceptionFile "/home/user1/miniconda3/lib/python3.7/concurrent/futures/thread.py", line 57, in runresult = self.fn(*self.args, **self.kwargs)File "/home/user1/miniconda3/lib/python3.7/site-packages/conda/core/subdir_data.py", line 98, in <lambda>package_ref_or_match_spec))File "/home/user1/miniconda3/lib/python3.7/site-packages/conda/core/subdir_data.py", line 110, in queryself.load()File "/home/user1/miniconda3/lib/python3.7/site-packages/conda/core/subdir_data.py", line 174, in load_internal_state = self._load()File "/home/user1/miniconda3/lib/python3.7/site-packages/conda/core/subdir_data.py", line 248, in _loadrepodata_fn=self.repodata_fn)File "/home/user1/miniconda3/lib/python3.7/site-packages/conda/core/subdir_data.py", line 470, in fetch_repodata_remote_requestsession = CondaSession()File "/home/user1/miniconda3/lib/python3.7/site-packages/conda/gateways/connection/session.py", line 54, in __call__session = cls._thread_local.session = super(CondaSessionType, cls).__call__()File "/home/user1/miniconda3/lib/python3.7/site-packages/conda/gateways/connection/session.py", line 87, in __init__self.headers['User-Agent'] = context.user_agentFile "/home/user1/miniconda3/lib/python3.7/site-packages/conda/_vendor/auxlib/decorators.py", line 268, in new_fgetcache[inner_attname] = func(self)File "/home/user1/miniconda3/lib/python3.7/site-packages/conda/base/context.py", line 741, in user_agentbuilder.append("%s/%s" % self.os_distribution_name_version)File "/home/user1/miniconda3/lib/python3.7/site-packages/conda/_vendor/auxlib/decorators.py", line 268, in new_fgetcache[inner_attname] = func(self)File "/home/user1/miniconda3/lib/python3.7/site-packages/conda/base/context.py", line 783, in os_distribution_name_versionfrom .._vendor.distro import id, versionFile "/home/user1/miniconda3/lib/python3.7/site-packages/conda/_vendor/distro.py", line 1084, in <module>_distro = LinuxDistribution()File "/home/user1/miniconda3/lib/python3.7/site-packages/conda/_vendor/distro.py", line 600, in __init__if include_lsb else {
    }File "/home/user1/miniconda3/lib/python3.7/site-packages/conda/_vendor/distro.py", line 943, in _get_lsb_release_inforaise subprocess.CalledProcessError(code, cmd, stdout, stderr)subprocess.CalledProcessError: Command 'lsb_release -a' returned non-zero exit status 1.

原因:lsb_release.py这个东西貌似有问题。从conda的报错信息里面也能看出来。
解决:

$ sudo vi /usr/share/pyshared/lsb_release.py
把 48 行 
从
RELEASES_ORDER.sort(key=lambda n: float(n[0]))
改成
RELEASES_ORDER.sort(key=lambda n: float(n[0].split()[0]))

然后lsb_release可以用了,conda也可以用了

$ lsb_release -a
LSB Version:    security-11.1.0ubuntu2-noarch
Distributor ID: Ubuntu
Description:    Ubuntu 16.04 LTS
Release:        16.04
Codename:       n/a

感谢:https://askubuntu.com/questions/930837/lsb-release-could-not-convert-string-to-float-8-04-lts

  相关解决方案