在安装好Anaconda后输入conda activate可能会出现下面的情况:
本人之前的报错已经消失了,故这里的报错借鉴CSDN博主代码小白阿斌的文章,报错的格式也是这个文章链接为https://blog.csdn.net/qq_39169223/article/details/112392253
```powershell
F:\pythonwork>conda deactivate
F:\pythonwork>conda activate
(base) F:\pythonwork>conda activate py37
WARNING conda.exceptions:print_unexpected_error_report(1213): KeyError('pkgs_dirs')
Traceback (most recent call last):
File "D:\Anaconda\lib\site-packages\conda\cli\main.py", line 140, in main
return activator_main()
File "D:\Anaconda\lib\site-packages\conda\activate.py", line 1210, in main
print(activator.execute(), end='')
File "D:\Anaconda\lib\site-packages\conda\activate.py", line 178, in execute
return getattr(self, self.command)()
File "D:\Anaconda\lib\site-packages\conda\activate.py", line 152, in activate
builder_result = self.build_activate(self.env_name_or_prefix)
File "D:\Anaconda\lib\site-packages\conda\activate.py", line 300, in build_activate
return self._build_activate_stack(env_name_or_prefix, False)
File "D:\Anaconda\lib\site-packages\conda\activate.py", line 314, in _build_activate_stack
prefix = locate_prefix_by_name(env_name_or_prefix)
File "D:\Anaconda\lib\site-packages\conda\base\context.py", line 1429, in locate_prefix_by_name
envs_dirs = context.envs_dirs
File "D:\Anaconda\lib\site-packages\conda\base\context.py", line 507, in envs_dirs
return mockable_context_envs_dirs(self.root_writable, self.root_prefix, self._envs_dirs)
File "D:\Anaconda\lib\site-packages\conda\base\context.py", line 88, in mockable_context_envs_dirs
fixed_dirs += join(user_data_dir(APP_NAME, APP_NAME), 'envs'),
File "D:\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:\Anaconda\lib\site-packages\conda\_vendor\appdirs.py", line 284, in _get_win_folder_with_pywin32
from win32com.shell import shellcon, shell
ImportError: DLL load failed: 找不到指定的程序。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Anaconda\lib\site-packages\conda\exceptions.py", line 1211, in print_unexpected_error_report
message_builder.append(get_main_info_str(error_report['conda_info']))
File "D:\Anaconda\lib\site-packages\conda\cli\main_info.py", line 238, in get_main_info_str
info_dict['_' + key] = ('\n' + 26 * ' ').join(info_dict[key])
KeyError: 'pkgs_dirs'
# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<
Traceback (most recent call last):
File "D:\Anaconda\lib\site-packages\conda\cli\main.py", line 140, in main
return activator_main()
File "D:\Anaconda\lib\site-packages\conda\activate.py", line 1210, in main
print(activator.execute(), end='')
File "D:\Anaconda\lib\site-packages\conda\activate.py", line 178, in execute
return getattr(self, self.command)()
File "D:\Anaconda\lib\site-packages\conda\activate.py", line 152, in activate
builder_result = self.build_activate(self.env_name_or_prefix)
File "D:\Anaconda\lib\site-packages\conda\activate.py", line 300, in build_activate
return self._build_activate_stack(env_name_or_prefix, False)
File "D:\Anaconda\lib\site-packages\conda\activate.py", line 314, in _build_activate_stack
prefix = locate_prefix_by_name(env_name_or_prefix)
File "D:\Anaconda\lib\site-packages\conda\base\context.py", line 1429, in locate_prefix_by_name
envs_dirs = context.envs_dirs
File "D:\Anaconda\lib\site-packages\conda\base\context.py", line 507, in envs_dirs
return mockable_context_envs_dirs(self.root_writable, self.root_prefix, self._envs_dirs)
File "D:\Anaconda\lib\site-packages\conda\base\context.py", line 88, in mockable_context_envs_dirs
fixed_dirs += join(user_data_dir(APP_NAME, APP_NAME), 'envs'),
File "D:\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:\Anaconda\lib\site-packages\conda\_vendor\appdirs.py", line 284, in _get_win_folder_with_pywin32
from win32com.shell import shellcon, shell
ImportError: DLL load failed: 找不到指定的程序。
`$ D:\Anaconda\Scripts\conda-script.py shell.cmd.exe activate py37`
environment variables:
conda info could not be constructed.
KeyError('pkgs_dirs')
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?
从上面的报错最后一段可以看到有一句
from win32com.shell import shellcon, shell
ImportError: DLL load failed: 找不到指定的程序。
然后在这段提示下面给出了文件路径
D:\Anaconda\Scripts\conda-script.py shell.cmd.exe
顺着文件路径寻找后发现并没有shell文件,于是打开cmd输入:
pip uninstall pywin32
成功卸载后再次安装:
pip install pywin32
最后再次输入conda activate
就可以激活当前环境,不会再发生报错。