如何阻止VS Code打开终端时自动执行conda activate命令
阻止VS Code打开终端时自动运行
conda activate的方法 方法一:移除Conda自动初始化代码
Conda首次初始化时会向shell配置文件添加启动代码,VS Code终端启动时会加载这些配置文件,从而触发conda activate。解决步骤:
- 打开对应shell的配置文件:
- PowerShell:运行
notepad $PROFILE打开用户配置文件 - WSL(bash):运行
nano ~/.bashrc打开配置文件;若用zsh则编辑~/.zshrc - CMD:检查
%USERPROFILE%目录下的_init.bat或autoexec.bat文件
- PowerShell:运行
- 在文件中找到被
# >>> conda initialize >>>和# <<< conda initialize <<<包裹的代码块,直接删除或用#注释掉整段代码 - 保存文件后,重启VS Code和终端
方法二:修改VS Code终端启动参数
让VS Code终端启动时跳过加载shell配置文件,避免执行conda初始化代码:
- 打开VS Code设置(快捷键
Ctrl+,/Cmd+,),搜索terminal.integrated.shellArgs - 根据使用的终端类型添加参数:
- PowerShell:在
terminal.integrated.shellArgs.windows中添加-NoProfile - WSL:在
terminal.integrated.shellArgs.linux中添加--noprofile --norc - CMD:在
terminal.integrated.shellArgs.windows中添加/d
- PowerShell:在
- 也可直接编辑
settings.json(快捷键Ctrl+Shift+P输入Preferences: Open Settings (JSON)),添加对应配置:// PowerShell 配置示例 "terminal.integrated.shellArgs.windows": ["-NoProfile"], // WSL bash 配置示例 "terminal.integrated.shellArgs.linux": ["--noprofile", "--norc"], // CMD 配置示例 "terminal.integrated.shellArgs.windows": ["/d"]
方法三:关闭Python扩展的自动环境激活
若安装了VS Code的Python扩展,它可能会自动激活conda环境:
- 在VS Code设置中搜索
python.terminal.activateEnvironment,将其设置为false - 对应的
settings.json配置:"python.terminal.activateEnvironment": false
内容的提问来源于stack exchange,提问作者DLT
相关产品推荐
相关产品推荐

