Bootstrap

An unexpected error has occurred. Conda has prepared the above report.输入任意Conda指令报错。

1.问题描述(建议看一下是否是自己的问题)

当进入Ubuntu环境时,调用conda info --envs 命令查看已有conda环境时,出现以下错误。

# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<

    Traceback (most recent call last):
      File "/home/star/envs/lib/python3.7/site-packages/conda/cli/main.py", line 97, in main
        from ..activate import main as activator_main
      File "/home/star/envs/lib/python3.7/site-packages/conda/activate.py", line 15, in <module>
        context.__init__()  # oOn import, context does not include SEARCH_PATH. This line fixes that.
      File "/home/star/envs/lib/python3.7/site-packages/conda/base/context.py", line 237, in __init__
        argparse_args=argparse_args)
      File "/home/star/envs/lib/python3.7/site-packages/conda/common/configuration.py", line 722, in __init__
        self._set_search_path(search_path)
      File "/home/star/envs/lib/python3.7/site-packages/conda/common/configuration.py", line 728, in _set_search_path
        self._set_raw_data(load_file_configs(search_path))
      File "/home/star/envs/lib/python3.7/site-packages/conda/common/configuration.py", line 369, in load_file_configs
        raw_data = odict(kv for kv in chain.from_iterable(load_paths))
      File "/home/star/envs/lib/python3.7/site-packages/conda/common/configuration.py", line 369, in <genexpr>
        raw_data = odict(kv for kv in chain.from_iterable(load_paths))
      File "/home/star/envs/lib/python3.7/site-packages/conda/common/configuration.py", line 344, in _file_yaml_loader
        yield fullpath, YamlRawParameter.make_raw_parameters_from_file(fullpath)
      File "/home/star/envs/lib/python3.7/site-packages/conda/common/configuration.py", line 332, in make_raw_parameters_from_file
        ruamel_yaml = yaml_load(fh)
      File "/home/star/envs/lib/python3.7/site-packages/conda/common/serialize.py", line 54, in yaml_load
        return yaml.load(string, Loader=yaml.RoundTripLoader, version="1.2")
      File "/home/star/envs/lib/python3.7/site-packages/ruamel/yaml/main.py", line 1085, in load
        error_deprecation('load', 'load', arg=_error_dep_arg, comment=_error_dep_comment)
      File "/home/star/envs/lib/python3.7/site-packages/ruamel/yaml/main.py", line 1037, in error_deprecation
        raise AttributeError(s)
    AttributeError: 
    "load()" has been removed, use
    
      yaml = YAML(typ='rt')
      yaml.load(...)
    
    and register any classes that you use, or check the tag attribute on the loaded data,
    instead of file "/home/star/envs/lib/python3.7/site-packages/conda/common/serialize.py", line 54
    
        return yaml.load(string, Loader=yaml.RoundTripLoader, version="1.2")
    
    

`$ /home/star/envs/bin/conda shell.posix activate base`

  environment variables:
                 CIO_TEST=<not set>
          CONDA_CHANGEPS1=true
                CONDA_EXE=/home/star/envs/bin/conda
               CONDA_HOME=/home/star/envs
             CONDA_PREFIX=/home/star/envs
             CONDA_PYTHON=/home/star/envs/bin/python
         CONDA_PYTHON_EXE=/home/star/envs/bin/python
               CONDA_ROOT=/home/star/envs
              CONDA_SHLVL=0
          LD_LIBRARY_PATH=/usr/local/cuda/lib64
                     PATH=/home/star/envs/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:
                          /sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/star/data/cxy/n
                          ode-v18.18.0-linux-x64/bin:/home/star/envs/bin:/home/star/envs/bin/con
                          da:/home/star/envs:/home/star/envs/bin/python:/home/star/envs/bin/pyth
                          on:/usr/local/cuda/bin
       REQUESTS_CA_BUNDLE=<not set>
            SSL_CERT_FILE=<not set>

     active environment : base
    active env location : /home/star/envs
            shell level : 0
       user config file : /home/star/.condarc
 populated config files : 
          conda version : 4.5.11
    conda-build version : 3.15.1
         python version : 3.7.0.final.0
       base environment : /home/star/envs  (writable)
           channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/free/linux-64
                          https://repo.anaconda.com/pkgs/free/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
                          https://repo.anaconda.com/pkgs/pro/linux-64
                          https://repo.anaconda.com/pkgs/pro/noarch
          package cache : /home/star/envs/pkgs
                          /home/star/.conda/pkgs
       envs directories : /home/star/envs/envs
                          /home/star/.conda/envs
               platform : linux-64
             user-agent : conda/4.5.11 requests/2.31.0 CPython/3.7.0 Linux/5.15.0-88-generic ubuntu/20.04 glibc/2.31
                UID:GID : 1000:1000
             netrc file : None
           offline mode : False


An unexpected error has occurred. Conda has prepared the above report.
If submitted, this report will be used by core maintainers to improve
future releases of conda.
Would you like conda to send this report to the core maintainers?
[y/N]: 
No report sent. To permanently opt-out, use

    $ conda config --set report_errors false

通过报错信息得知,错误的点存在以下两个:

  • 关于ruamel.yaml的调用错误
AttributeError: 
    "load()" has been removed, use
    
      yaml = YAML(typ='rt')
      yaml.load(...)
    
    and register any classes that you use, or check the tag attribute on the loaded data,
    instead of file "/home/star/envs/lib/python3.7/site-packages/conda/common/serialize.py", line 54
    
        return yaml.load(string, Loader=yaml.RoundTripLoader, version="1.2")
  • conda命令发生预期之外的错误
An unexpected error has occurred. Conda has prepared the above report

另外,日常正确的加载情况应该如下,直接激活conda的base环境,如下所示。但是报错的时候并没有(base)

(base) star@b404-3090:~$

2. 解决办法

注:我的conda安装目录是/home/star/envs 请自行比对

第一步:通过以下命令检查conda相关信息

export

返回信息如下所示:

(base) star@b404-3090:~$ export
declare -x CONDA_DEFAULT_ENV="base"
declare -x CONDA_EXE="/home/star/envs/bin/conda"
declare -x CONDA_HOME="/home/star/envs"
declare -x CONDA_PREFIX="/home/star/envs"
declare -x CONDA_PROMPT_MODIFIER="(base) "
declare -x CONDA_PYTHON="/home/star/envs/bin/python"
declare -x CONDA_PYTHON_EXE="/home/star/envs/bin/python"
declare -x CONDA_SHLVL="1"
declare -x CUDA_VISIBLE_DEVICES="0,1,2"

请确认以上有关CONDA的字段指向的路径是你conda正确安装的路径。再次强调,我的conda安装路径是/home/star/envs,请自己比对后修改以上字段。

第二步:通过以下命令修改不正确的字段

# vim 是编辑器,如果有其他的编辑器例如nano也可以使用
sudo vim /etc/profile

# 然后再/etc/profile文件中添加需要修改的内容,根据自己的实际情况
export NODE_HOME=/home/star/data/cxy/node-v18.18.0-linux-x64
export PATH=$PATH:$NODE_HOME/bin
export CONDA_HOME=/home/star/envs
export PATH=$PATH:$CONDA_HOME/bin
export CONDA_EXE=/home/star/envs/bin/conda
export PATH=$PATH:$CONDA_EXE
export CONDA_PREFIX=/home/star/envs
export PATH=$PATH:$CONDA_PREFIX
export CONDA_PYTHON=/home/star/envs/bin/python

# 修改完毕后,输入以下命令使其生效
source /etc/profile

# 使用export 再次查看更改是否生效

小插曲

我更改完环境变量后,在export命令返回的内容中是正确的,但是使用conda命令时出现

-bash: /home/star/anaconda3/bin/conda: 没有那个文件或目录

这是因为我的服务器中安装了两个anaconda,这个anaconda3是后面安装的,也许覆盖掉了之前的安装路径,但是我也找不到它具体是哪个变量绑定的,所以通过别名的方式进行修改,如果你也有一样的问题,可以尝试

# 注 envs是我最早安装的,anaconda3是后面安装的,所以这条指令的目的是使得conda指向最初的envs安装目录。
alias conda='/home/star/envs/bin/conda'

第三步: 确保文件有执行权限

# 使用以下指令添加权限
chmod +x /home/star/envs/bin/conda

第四步:检查是否存在ruamel包

# 如果看见了ruamel那就是已经有了,但是报错一般来说是没有的
conda list | grep "ruamel"

第四步:下载ruamel文件

打开链接:ruamel下载
由于服务器当前处于断网的情况,所以我是通过在本地下载之后,通过Xftp上传到服务器的。如果你的服务器连接了网络,那么你可以通过wget 或者curl命令下载

第五步: 安装ruamel文件

使用mv命令将第四步下载的ruamel文件移动到conda安装目录下的bin目录中,我的是/home/star/envs/bin,请自行比对,移动完毕后,通过pip install 下载的文件名.whl命令进行安装。

第六步:查看是否安装成功

(base) star@b404-3090:~$ conda list |grep "ruamel"
ruamel.yaml               0.17.21                   <pip>
ruamel.yaml.clib          0.2.8                     <pip>
ruamel_yaml               0.15.46          py37h14c3975_0    https://repo.anaconda.com/pkgs/main

安装成功!到此,重新连接,就会发现再次进入时已经没有报错,并且初始是base环境~

3. 致谢

感谢热心市民BIN!!!

;