Charlie Parker
Charlie Parker

Reputation: 5199

How to have conda commands match behaviour in Vscode's integrated terminal and normal terminal?

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:


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.

Upvotes: 3

Views: 1664

Answers (2)

spazm
spazm

Reputation: 4809

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

Upvotes: 1

Max Uppenkamp
Max Uppenkamp

Reputation: 974

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

Upvotes: 1

Related Questions