Vaibhav Bhavsar
Vaibhav Bhavsar

Reputation: 199

How to avoid conda activate base from automatically executing in my VS Code editor?

PS E:\Python and Data Science\PythonDatabase> conda activate base
conda : The term 'conda' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling    
of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ conda activate base
+ ~~~~~
    + CategoryInfo          : ObjectNotFound: (conda:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS E:\Python and Data Science\PythonDatabase> & C:/Users/Lenovo/Anaconda3/python.exe "e:/Python and Data Science/PythonDatabase/CourseHelper.py"
Hello World
PS E:\Python and Data Science\PythonDatabase> 

Upvotes: 16

Views: 14044

Answers (2)

mherzog
mherzog

Reputation: 1230

Building on @Brett Cannon's answer...

You have 2 options. Unless otherwise noted, all of the following assume you are changing VSCode Settings (F1 -> Terminal:Configure Terminal Settings).

Option 1

Use the Command Prompt instead of PowerShell.

  1. Switch your VSCode terminal to the Command Prompt enter image description here
  2. In the settings.json file, set the "python.condaPath" to your conda.exe. E.g.
"python.condaPath": "C:\\Users\\<user id>\\Anaconda3\\Scripts\\conda.exe"

Option 2

Set the PATH variable.

  1. Add the path to conda.exe to your PATH environment variable (per https://stackoverflow.com/a/66259191/11262633):
    "terminal.integrated.env.windows": {
            "PATH": "${env:PATH};C:\\Users\\<user id>\\Anaconda3\\Scripts"
    }
  1. Start a PowerShell terminal. You will get a message stating that Conda has not been initialized. Run the following command:
conda init

Note that as of the writing of this answer, conda init --help states that this command is experimental.

MicroSoft states that VSCode doesn't currently support automatically activating Conda environments using PowerShell. However, option 2 seems to work.

Upvotes: 0

Brett Cannon
Brett Cannon

Reputation: 16080

You can set "python.terminal.activateEnvironment": false in your settings to deactivate activation of your environment. Alternatively, you can set "python.condaPath" to where conda exists so the extension can use conda appropriately.

Upvotes: 26

Related Questions