Visual Studio 代码集成终端路径不同于普通终端

Bad*_*ssi 1 path .bash-profile visual-studio-code macos macos-mojave

我在 MacOS Mojave 上,我无法弄清楚为什么 Visual Studio Code 的集成终端与普通终端具有不同的路径变量。

我已经检查过 VSCode 是否打开/bin/bashecho $SHELLyields /bin/bash)。

但是,echo $PATH在集成终端中执行时,它/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/anaconda3/bin:/anaconda3/condabin会在正常终端上产生/anaconda3/bin:/anaconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

它们都~/.bash_profile包含以下内容:

# added by Anaconda3 2018.12 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
    \eval "$__conda_setup"
else
    if [ -f "/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/anaconda3/etc/profile.d/conda.sh"
        CONDA_CHANGEPS1=false conda activate base
    else
        \export PATH="/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
Run Code Online (Sandbox Code Playgroud)

即使在~/.bash_profile集成终端中采购之后, /anaconda3/bin 也在最后,而在~/.bash_profile前面加上它,这令人困惑。

我认为在集成终端中获取 bash_profile 后必须添加默认路径?不确定它是如何工作的

我犹豫是否将此作为问题发布到 vscode 存储库中,但我只是想确保这不是我的理解。

小智 5

在 Visual Studio Code 中,从命令面板 (??P) 打开 Settings (JSON),并在文件末尾添加以下内容

"terminal.integrated.env.osx": {
        "PATH": ""
}
Run Code Online (Sandbox Code Playgroud)

重新启动 VSCode,一切就绪。

摘自https://github.com/Microsoft/vscode-python/issues/4434


Gor*_*son 5

您可以在 Visual Studio Code 设置中取消选中Terminal \xe2\x80\xba Integrated: Inherit Env选项,该选项可以通过 进行搜索terminal.integrated.inheritEnv,如下图所示:

\n

在此输入图像描述

\n

参考: https: //github.com/microsoft/vscode/issues/70248#issuecomment-502186149(现在该选项terminal.integrated.inheritEnv包含在稳定版本中。)

\n