2

In my console (iterm2) which python gives /Users/anders/anaconda3/bin/python

In Visual Studio Code's built in terminal which python gives /usr/bin/python

Since I want to use anacondas python installation I use CMD+SHIFT+P(Python: Select Interpreter) and there I see ~/anaconda3/bin/python so I select that one.

However this does not take effect in my terminal. I have tried the following to make it reflect when doing which python

  • Open a new terminal tab
  • Restart program

And if I go back to confirm active interpreter, it does say anaconda. But still it uses the one from /usr/bin/python. Whats going on here?

update

echo $PATH in visual studio code

/usr/local/opt/node@8/bin:
/usr/local/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin:
~/bin:
/Users/anders/anaconda3/bin:
/usr/local/opt/node@8/bin:
/Users/anders/.composer/vendor/bin:
/Users/anders/.composer/vendor/bin

echo $PATH in iterm2

/Users/anders/anaconda3/bin:
/usr/local/opt/node@8/bin:
/usr/local/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin:
~/bin:
/Users/anders/.composer/vendor/bin

So VS code does something to my PATH but I don't see the pattern.

echo $SHELL gives /bin/bash Putting export SHELL="/Applications/iTerm.app/Contents/MacOS/iTerm2" in my bash_profile does make VS code to open iterm2 on CMD+ALT+C, but not when switching to the integrated terminal.

I put the following settings in Visual studio code settings (CMD+,)

  • Terminal: Explorer Kind external
  • Terminal>External: Osx Exec /Applications/iTerm.app/Contents/MacOS/iTerm2

Also tried

  • Terminal: Explorer Kind integrated
  • Terminal>External: Osx Exec /Applications/iTerm.app/Contents/MacOS/iTerm2

but both of them spawns a new iTerm window that is not integrated.

  • If downvoting, can you please tell me how to improve the question? – Anders Dec 4 '18 at 13:14
  • 1
    I couldn't find a tool called visual code. Are you referring to this? code.visualstudio.com/docs/python/environments – tink Dec 10 '18 at 3:24
  • 1
    And did the link about the environments shed any light on your problem? – tink Dec 10 '18 at 3:29
  • Thanks, though not really. As the documentation says: "opening a terminal with the Terminal: Create New Integrated Terminal command. In the latter case, VS Code automatically activated the selected environment". But im still getting the default interpreter. – Anders Dec 10 '18 at 3:38
  • The $PATH environment variable is order specific. In your example where it is working, the $PATH has /Users/anders/anaconda3/bin before /usr/bin. Try setting the $PATH of visual studio code to have your Anaconda directory as the first path and then see if you get the behavior you are expecting. – GracefulRestart Dec 10 '18 at 21:35
2
+50

Maybe Virtual Studio Code does not use the same shell that you're using with iTerm2? According to the docs on the integrated terminal, the shell that is being used is the one which is set by the $SHELL environment variable. Inspect it with:

echo $SHELL

Furthermore, which scans your $PATH for an executable and return the first one found. So compare your settings there, too:

echo $PATH

If that is the issue, you can change $PATH, so it will find the python in /Users/anders/anaconda3/bin instead of /usr/bin.

Finally, it might help you to set an alias for python in the Visual Studio Code integrated terminal. You can set that up with:

$ alias python
bash: alias: python: not found
$ alias python=/Users/anders/anaconda3/bin/python
$ alias python
alias python='/Users/anders/anaconda3/bin/python'

(which might still show the other path, but if you run python, you'll get the one from the alias.)

  • Thanks for all the pointers! Yes, did resort to an alias, but it bugs me and would rather like to configure it to work properly. Please see updated question for some more clues. – Anders Dec 10 '18 at 3:30
  • Yes, it is VS code that prepends these paths to PATH when integratd terminal is launched so I dont know how to prevent that. Updating question with what happen when itegrated terminal config is set. – Anders Dec 11 '18 at 5:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.