未通过Anaconda Navigator启动VSCode时,如何解决base conda无法调用问题?
解决直接启动VSCode无法调用conda的问题
报错信息:
conda : The term 'conda' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 - conda activate base - + CategoryInfo : ObjectNotFound: (conda:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
以下是无需通过Anaconda Navigator启动VSCode即可正常使用base conda的解决方法:
刷新环境变量并重启VSCode
- 关闭所有VSCode窗口和正在运行的终端
- 打开管理员权限的CMD,执行
refreshenv命令;如果用PowerShell,执行$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") - 直接从开始菜单或桌面快捷方式启动VSCode
初始化conda到终端
- 打开Anaconda Prompt(该环境下conda命令默认可用)
- 根据常用终端执行对应命令:
- PowerShell:
conda init powershell - CMD:
conda init cmd.exe - Git Bash:
conda init bash
- PowerShell:
- 重启终端和VSCode,之后直接启动VSCode即可识别conda命令
检查VSCode终端默认配置
- 打开VSCode设置(快捷键
Ctrl+,),搜索terminal.integrated.defaultProfile.windows - 确认默认终端是已初始化conda的类型(比如PowerShell或CMD)
- 若之前用的是未初始化的终端,切换后重启VSCode即可
- 打开VSCode设置(快捷键
验证conda路径正确性
- 确认系统环境变量Path中添加的是conda的
Scripts目录,示例路径:C:\Users\你的用户名\anaconda3\Scripts - 在CMD中直接输入该路径下的
conda.exe,若能正常运行,说明路径无误,只需按前面的步骤刷新环境变量或初始化终端
- 确认系统环境变量Path中添加的是conda的
内容的提问来源于stack exchange,提问作者xminx
相关产品推荐
相关产品推荐

