错误由来
服务器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 也不报错了。又能愉快的创建环境了!
参考
- https://stackoverflow.com/questions/16069816/getting-python-error-from-cant-read-var-mail-bio
- https://blog.csdn.net/weixin_41216652/article/details/132117962