3

I was put off because conda info --envs does NOT display the same thing that my terminal does. Terminal:

(automl) brandBrandoParetoopareto~/anaconda3/envs $ conda info --envs
# conda environments:
#
base                     /Users/brandBrandoParetoopareto/anaconda3
automl                *  /Users/brandBrandoParetoopareto/anaconda3/envs/automl
coqgym                   /Users/brandBrandoParetoopareto/anaconda3/envs/coqgym

vscode integrated terminal outpute:

(automl) brandBrandoParetoopareto~/ultimate-utils $ conda info --envs
# conda environments:
#
                         /Users/brandBrandoParetoopareto/anaconda3
base                  *  /Users/brandBrandoParetoopareto/anaconda3/envs/automl
                         /Users/brandBrandoParetoopareto/anaconda3/envs/coqgym

it is really strange because it seems to be using the right env which I would have not know because in the debugger window it does not show (automl) but says (base) but points to the right env (In fact the previous command output if you read it carefully says it's using (automl) but then it's actually using base BUT it seems to be pointing to the right environment!?!? But wrong names).

This seems like weird behavior does anyone know how to fix this or if it's causing other unexpected issues?

Perhaps this should be posted in vscode issues but I couldn't figure out which one since there is a vscode and a vscode-python one too.


Related issue:

  • I initially saw this issue Conda and Visual Studio Code debugging because I thought since it was pointing at base (or at least displaying wrong names) that it didn't recognize or know where my conda path was so that question seemed useful but ended up not fixing the naming issues.
  • Initially I also thought that it might have been related to a conda init issue I had exactly 30 days ago but it wasn't related unfortuantely Why is conda init updating my .bash_profile incorrectly?

Per comment request to check inheritEnv (to get to it go to settings then in search bar type inheritEnv):

enter image description here

the box is unchecked which I assume means "terminal.integrated.inheritEnv" is set to false


The weird thing I am seeing now is that:

  1. the bottom conda right option to select environments, the environment I want to use does NOT appear. Even when I paste the path to it's option it does not work.
  2. When I start a new terminal, somehow it decides to activate base by it's own eventhough my zsh already starts using the correct environment. Why is that? But even when I do zsh to start a new prompt, the bottom left does not seem to point to the right conda env.
Charlie Parker
  • 5,884
  • 57
  • 198
  • 323

2 Answers2

1

My recommendation would be to simply set VS Code to use the shell you are using normally: How to change the integrated terminal in visual studio code or VSCode

Max Uppenkamp
  • 974
  • 4
  • 16
  • what do you mean by "My recommendation would be to simply set VS Code to use the shell you are using normally"? – Charlie Parker Jun 09 '20 at 17:21
  • Can you explain how your suggestion would solve my problem and why? – Charlie Parker Jun 09 '20 at 17:36
  • I think this is what I need to do if I want to follow your suggestion but I've not tested it since Im not sure what to expect: changing this: ` "terminal.integrated.automationShell.osx": "PUT PATH TO YOUR SHELL HERE"` – Charlie Parker Jun 09 '20 at 17:37
  • This simply switches out the default shell that VS Code uses to the one you specify. If you have your shell config set up properly, this should perfectly match the expected behavior, since it's the same code. – Max Uppenkamp Jun 10 '20 at 11:57
1

Have you set the python environment in VScode? If not explicitly it picks the first python it can find according to it's python search algorithm.

The Status Bar always shows the current interpreter.

Image showing interpreter in status bar, next to warning and error icons

To select a specific environment, use the Python: Select Interpreter command from the Command Palette (Ctrl+Shift+P). annotated screenshot of found environments

This interpreter will be saved in the workspace settings:

Selecting an interpreter from the list adds an entry for python.pythonPath with the path to the interpreter inside your Workspace Settings. Because the path is part of the workspace settings, the same environment should already be selected whenever you open that workspace. If you'd like to set up a default interpreter for your applications, you can instead add an entry for python.pythonPath manually inside your User Settings. To do so, open the Command Palette (Ctrl+Shift+P) and enter Preferences: Open User Settings. Then set python.pythonPath, which is in the Python extension section of User Settings, with the appropriate interpreter.

Caveats:

Conda environments can't be automatically activated in the VS Code Integrated Terminal if the default shell is set to PowerShell. To change the shell, see Integrated terminal - Configuration.

Conda environment in your project will be used, but only if the conda environment contains the python interpreter, by setting python= when creating the conda environment:

conda create -n env-01 python=3.4

For further details check the python environments section of the VSCode documentation. https://code.visualstudio.com/docs/python/environments

spazm
  • 4,399
  • 31
  • 30
  • My vs-code still does not display at the bottom the right environment (despite the terminal prompt showing the name of the environment). I tried copy pasting the path to where you enter the interpreter path but it did not work. I'm unsure what to try. – Charlie Parker Jun 09 '20 at 17:22
  • When I start a new terminal, somehow vscode decides to activate base by it's own eventhough my zsh already starts using the correct environment. Why is that? But even when I do `zsh` to start a new prompt, the bottom left does not seem to point to the right conda env. – Charlie Parker Jun 09 '20 at 17:26
  • Ok it seems that restarting vscode from a normal terminal when the environment I want to use is activated made vscode recognize the environment and now it appears as an options. Sometimes vscode is such a pain and mysterious, but somehow restarting it has solved my issues more than once. – Charlie Parker Jun 09 '20 at 17:34