0

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?

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.

EDIT: 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.

Wolfy
  • 1,445
  • 1
  • 14
  • 28
  • The two are identical on my linux box, so I'm not the best help :-P, but I would suspect vscode might be configured to run a login shell, thus reading ~/.profile or ~/.zprofile instead of ~/.zshrc – Christian Fosli Apr 16 '21 at 18:05

2 Answers2

4

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
Wolfy
  • 1,445
  • 1
  • 14
  • 28
  • It gets scrambled within a sub-shell of VS Code on macOS because macOS by default constructs the PATH from `/etc/paths` and `/etc/paths.d/*` via a call to `/usr/libexec/path_helper` within the shell's profile. (Thanks to the excellent explanation from here: https://scriptingosx.com/2017/05/where-paths-come-from/ ) – Tim Lewis Oct 20 '22 at 14:30
0

I am not 100% sure the right behaviour as I don't use a Mac but you might try launching VS Code from the terminal which has the right environment. Make sure that code is in your PATH with https://code.visualstudio.com/docs/setup/mac#_launching-from-the-command-line

Then ensure that all the VScode sessions are closed on your machine and launch it via code from the terminal.

tingleby
  • 1
  • 1
  • I tried that, but it doesn't make any difference. However, I restarted my laptop and received a "Resolving Shell Environment is Slow" message which led me to this article: https://code.visualstudio.com/docs/supporting/faq#_resolving-shell-environment-is-slow-error-warning Not very informative, though. – Wolfy Jun 02 '21 at 17:10