Visual Studio Code 中的 PATH 变量与 Mac 上的终端不同 [英] PATH variable in Visual Studio Code different from Terminal on Mac

查看:21
本文介绍了Visual Studio Code 中的 PATH 变量与 Mac 上的终端不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Visual Studio Code 中集成终端中的 PATH 变量与终端应用程序中的变量不同.我该如何更改?

The PATH variable in the integrated Terminal in Visual Studio Code is different from the one in the Terminal app. How can I change it?

我正在使用来自 Intel oneAPI 的 Intel Distribution for Python,并且在我的 .zshrc 中同时调用了 setvars.sh 脚本和 conda 初始化代码.在 Mac 终端中,我可以正确激活 conda 环境.但是,在VSC中的集成终端中,/usr/bin文件夹列在conda文件夹之前,因此调用了系统Python解释.

I'm using the Intel Distribution for Python from Intel oneAPI and I have both the setvars.sh script called and the conda initialize code in my .zshrc. In Mac Terminal I can properly activate conda environments. However, in the integrated Terminal in VSC, the /usr/bin folder is listed before the conda folders, so the system Python interpreted is called.

我最初认为英特尔 Python 发行版与此有关,但常规 Anaconda 发行版也会出现同样的问题.

I initially thought that the Intel Distribution for Python had something to do with it, but the same issue occurs with a regular Anaconda distribution.

推荐答案

看起来问题是 Visual Studio Code 从 Terminal 继承了 PATH 但不知何故它重新排列了文件夹的顺序,这混淆了 Anaconda 激活脚本.由于找不到解决方案,我通过在 Anaconda 初始化脚本之后将以下几行添加到我的 .zshrc 中来实现一种解决方法:

It looks like that the problem is that Visual Studio Code inherits the PATH from Terminal but somehow it rearranges the order of the folder, and this confuses the Anaconda activation script. Since I couldn't find a solution, I implemented a workaround by adding the following lines to my .zshrc, right after the Anaconda initialization script:

# Workaround for Visual Studio Code integrated terminal
if [[ -v VSCODE_GIT_IPC_HANDLE ]]; then
    conda deactivate
    conda activate
fi

这篇关于Visual Studio Code 中的 PATH 变量与 Mac 上的终端不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆