Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 746
Nanashi No Gombe Avatar asked Aug 06 '26 06:08

Nanashi No Gombe


1 Answers

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 :)

like image 86
Chih Fan Tang Avatar answered Aug 07 '26 19:08

Chih Fan Tang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!