VS Code中无法运行Python脚本求助:conda命令未被识别
解决VS Code中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
核心原因
VS Code的终端没加载conda的环境变量,其他IDE一般会自动配置好conda路径。
解决方法
确认conda安装路径
找到你的conda安装目录(通常是C:\Users\[你的用户名]\anaconda3或C:\Users\[你的用户名]\miniconda3),进入Scripts文件夹,确认里面有conda.exe文件。手动添加环境变量
- 右键「此电脑」→「属性」→「高级系统设置」→「环境变量」
- 在系统变量的
Path里添加两个路径:[conda安装目录]\Scripts[conda安装目录]\Library\bin
- 保存后重启VS Code。
让VS Code终端自动加载conda
- 打开VS Code设置(快捷键
Ctrl+,) - 搜索
terminal.integrated.shellArgs.windows(Windows系统),其他系统对应搜索关键词 - 将值设置为
["/K", "C:\Users\[你的用户名]\anaconda3\Scripts\activate.bat"],替换成自己的conda实际路径 - 重启终端,此时会自动激活base环境,直接用
conda命令就行。
- 打开VS Code设置(快捷键
临时应急方案
直接用conda的完整路径执行命令,示例:C:\Users\[你的用户名]\anaconda3\Scripts\conda.exe activate base
内容的提问来源于stack exchange,提问作者Zakaria Ait Yakoub
相关产品推荐
相关产品推荐

