不知道要拿来做什么但觉得很有意思的个人博客
Conda Error: KeyError: ‘pkgs_dirs’
Conda Error: KeyError: ‘pkgs_dirs’

Conda Error: KeyError: ‘pkgs_dirs’

报错信息

有一天准备用conda配置新的环境,结果conda突然各种报错,怎么都装不了。(我conda环境装在了 `D:\Software\Anaconda`)

ARNING conda.exceptions:print_unexpected_error_report(1257): KeyError('pkgs_dirs')
Traceback (most recent call last):
  File "D:\Softwares\Anaconda\lib\site-packages\conda\exceptions.py", line 1125, in __call__
    return func(*args, **kwargs)
  File "D:\Softwares\Anaconda\lib\site-packages\conda\cli\main.py", line 86, in main_subshell
    exit_code = do_call(args, p)
  File "D:\Softwares\Anaconda\lib\site-packages\conda\cli\conda_argparse.py", line 93, in do_call
    return getattr(module, func_name)(args, parser)
  File "D:\Softwares\Anaconda\lib\site-packages\conda\notices\core.py", line 72, in wrapper
    return_value = func(*args, **kwargs)
  File "D:\Softwares\Anaconda\lib\site-packages\conda\cli\main_create.py", line 23, in execute
    if is_conda_environment(context.target_prefix):
  File "D:\Softwares\Anaconda\lib\site-packages\conda\base\context.py", line 612, in target_prefix
    return determine_target_prefix(self)
  File "D:\Softwares\Anaconda\lib\site-packages\conda\base\context.py", line 1800, in determine_target_prefix
    return validate_prefix_name(prefix_name, ctx=ctx)
  File "D:\Softwares\Anaconda\lib\site-packages\conda\base\context.py", line 1761, in validate_prefix_name
    return locate_prefix_by_name(prefix_name)
  File "D:\Softwares\Anaconda\lib\site-packages\conda\base\context.py", line 1726, in locate_prefix_by_name
    envs_dirs = context.envs_dirs
  File "D:\Softwares\Anaconda\lib\site-packages\conda\base\context.py", line 538, in envs_dirs
    return mockable_context_envs_dirs(self.root_writable, self.root_prefix, self._envs_dirs)
  File "D:\Softwares\Anaconda\lib\site-packages\conda\base\context.py", line 110, in mockable_context_envs_dirs
    fixed_dirs += join(user_data_dir(APP_NAME, APP_NAME), 'envs'),
  File "D:\Softwares\Anaconda\lib\site-packages\conda\_vendor\appdirs.py", line 67, in user_data_dir
    path = os.path.join(_get_win_folder(const), appauthor, appname)
  File "D:\Softwares\Anaconda\lib\site-packages\conda\_vendor\appdirs.py", line 265, in _get_win_folder_with_pywin32
    from win32com.shell import shellcon, shell
ImportError: DLL load failed while importing shell: The specified procedure could not be found.

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "D:\Softwares\Anaconda\lib\site-packages\conda\exceptions.py", line 1255, in print_unexpected_error_report
    message_builder.append(get_main_info_str(error_report['conda_info']))
  File "D:\Softwares\Anaconda\lib\site-packages\conda\cli\main_info.py", line 237, in get_main_info_str
    info_dict['_' + key] = ('\n' + 26 * ' ').join(info_dict[key])
KeyError: 'pkgs_dirs'

百思不得其解。这里提供两个可能有用的网址。

https://stackoverflow.com/questions/61382692/anaconda-navigator-cannot-launch-from-win32com-shell-import-shellcon-shell

https://github.com/conda/conda/issues/9356

最终的解决方案

遵循上面的第一个链接的提示以及我最近配置vscode的情况,主要是通过以下几个步骤解决。

  1. 由于我之前vscode也安装了新的python,默认路径在user/Appdata下,我当时还为其设置了环境path。首先我们要讲这个路径的环境path删除,要不然这会导致在conda中的pip install指令全部都默认装到该python的site-packages目录下。默认是在AppData/Roaming/Python/下。
  2. 安装pywin32包,我按照第一个链接的指示,安装了 pip install pywin32=300,顺带装了个pip install pathli

装完之后就突然可以了,有点小神奇。

结论:捣鼓其他东西的时候记得不要乱给权限。

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注