解决‘Conda info 命令中lsb_release报错问题’

解决‘lsb_release报错问题’

错误由来

服务器Unbuntu中用Conda不能创建虚拟环境了,而且运行命令 conda info之后出现以下错误:

>>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<
Traceback (most recent call last):
  File "/opt/conda/lib/python3.10/site-packages/conda/exception_handler.py", line 16, in __call__
    return func(*args, **kwargs)
  File "/opt/conda/lib/python3.10/site-packages/conda/cli/main.py", line 84, in main_subshell
    exit_code = do_call(args, p)
  File "/opt/conda/lib/python3.10/site-packages/conda/cli/conda_argparse.py", line 126, in do_call
    return getattr(module, func_name)(args, parser)
  File "/opt/conda/lib/python3.10/site-packages/conda/cli/main_info.py", line 343, in execute
    info_dict = get_info_dict(args.system)
  File "/opt/conda/lib/python3.10/site-packages/conda/cli/main_info.py", line 184, in get_info_dict
    user_agent=context.user_agent,
  File "/opt/conda/lib/python3.10/site-packages/conda/auxlib/decorators.py", line 267, in new_fget
    cache[inner_attname] = func(self)
  File "/opt/conda/lib/python3.10/site-packages/conda/base/context.py", line 970, in user_agent
    builder.append("%s/%s" % self.os_distribution_name_version)
  File "/opt/conda/lib/python3.10/site-packages/conda/auxlib/decorators.py", line 267, in new_fget
    cache[inner_attname] = func(self)
  File "/opt/conda/lib/python3.10/site-packages/conda/base/context.py", line 1041, in os_distribution_name_version
    from conda._vendor.distro import id, version
  File "/opt/conda/lib/python3.10/site-packages/conda/_vendor/distro.py", line 1080, in <module>
    _distro = LinuxDistribution()
  File "/opt/conda/lib/python3.10/site-packages/conda/_vendor/distro.py", line 595, in __init__
    self._lsb_release_info = self._get_lsb_release_info() \
  File "/opt/conda/lib/python3.10/site-packages/conda/_vendor/distro.py", line 939, in _get_lsb_release_info
    raise subprocess.CalledProcessError(code, cmd, stdout, stderr)
subprocess.CalledProcessError: Command 'lsb_release -a' returned non-zero exit status 2.

网上相关的错误很少,我看到其中涉及到lsb_release -a这个命令,我单独运行这个命令后确实出现了错误,如下:

(base) root@adb846ce67f4:~# lsb_release -a
from: can't read /var/mail/optparse
/usr/bin/lsb_release: line 21: import: command not found
/usr/bin/lsb_release: line 22: import: command not found
/usr/bin/lsb_release: line 23: import: command not found
/usr/bin/lsb_release: line 25: import: command not found
/usr/bin/lsb_release: line 27: syntax error near unexpected token `('
/usr/bin/lsb_release: line 27: `def main():'

之后就去搜关于lsb_release的相关命令和常见错误。看到有一个相关的错误涉及到 from: can’t read /var/mailfrom: can’t read /var/mail/xxx。抱着试一试的想法去改了/usr/bin/lsb_release,文件中的开头第一行。
原来是:

#!/usr/bin/python3 -Es

# lsb_release command for Debian
# (C) 2005-10 Chris Lawrence <lawrencc@debian.org>

#    This package is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; version 2 dated June, 1991.
#    .........................................

后来把第一行改成 #!/usr/bin/env python3。
又出现了以下错误:

(base) root@adb846ce67f4:~# 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'

之后查看解决方法说是把系统完整的lsb_release.py文件拷贝到报错的目录文件下即可。我是把它放在了/usr/bin目录下。

在这里插入图片描述
之后问题解决,运行命令 : lsb_release -a 出现以下结果

(base) root@adb846ce67f4:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.6 LTS
Release:        20.04
Codename:       focal

之后运行conda info 和 conda create -n xxx python=xxx 也不报错了。又能愉快的创建环境了!

参考

  1. https://stackoverflow.com/questions/16069816/getting-python-error-from-cant-read-var-mail-bio
  2. https://blog.csdn.net/weixin_41216652/article/details/132117962
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值