Nanashi No Gombe
Nanashi No Gombe

Reputation: 620

Configuring the PATH variable in VS Code

I am using Microsoft Visual Studio Code 1.30.2 on macOS Mojave 10.14.3. In the settings of VS Code, I have required it to use the external Terminal.app application on macOS. I also have an Anaconda distribution of Python installed.

Note that the PATH variable here reads:

~ » $PATH
bash: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/anaconda3/bin:/anaconda3/condabin: No such file or directory

VS Code

The order above is different from what I get if I fire up the regular Terminal app and get the PATH.

~ » $PATH
-bash: /anaconda3/bin:/anaconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin: No such file or directory

Terminal.app

What this effectively does is switch the versions of Python when I type in python in the two cases. In the regular terminal, I get Python 3 right away, whereas in VS Code, I am faced with Python 2.

How do I change the PATH in VS Code so that whenever I type the words python, I am always given Python 3 instead of 2?


P.S. Please note that while editing Python code in VS Code, I can always select which interpreter I want to use, but that does not change the situation with the terminal underneath.

Upvotes: 3

Views: 21015

Answers (2)

Chih Fan Tang
Chih Fan Tang

Reputation: 26

I had the same problem, and I have a workaround solution.

I just add one line export PATH="/Users/username/anaconda3/bin:$PATH" into .bash_profile or .zshrc

The orifinal $PATH in vscode is /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/username/anaconda3/bin:/Users/username/anaconda3/condabin

And then my $PATH in vscode become /Users/username/anaconda3/envs/py36/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/username/anaconda3/bin:/Users/username/anaconda3/condabin

Please give it a try. I wish the workaround might help. Thanks :)

Upvotes: 1

Chris Larson
Chris Larson

Reputation: 1724

It sounds like your Workspace setting python.pythonPath is set explicitly to the /usr/bin. Set that to match your preferred $PATH and you should be good to go.

Go to Preferences in VS Code, search for python.pythonPath, switch to Workspace, and set as desired.

Upvotes: 0

Related Questions