Activating Anaconda Environment in VsCode
I have Anaconda working on my system and VsCode working, but how do I get VsCode to activate a specific environment when running my python script?
Solution 1:
Simply use
- shift + cmd + P
- Search Select Interpreter
- Select it and it will show you the list of your virtual environment created via conda and other python versions
- select the environment and you are ready to go.
Quoting the 'Select and activate an environment' docs
Selecting an interpreter from the list adds an entry for
python.pythonPath
with
the path to the interpreter inside your Workspace Settings.
Solution 2:
If Anaconda is your default Python install then it just works if you install the Microsoft Python extension.
The following should work regardless of Python editor or if you need to point to a specific install:
In settings.json edit python.path with something like
"python.pythonPath": "C:\\Anaconda3\\envs\\py34\\python.exe"
Instructions to edit settings.json
Solution 3:
The best option I found is to set the python.venvPath
parameter in vscode settings to your anaconda envs folder.
"python.venvPath": "/Users/[...]/Anaconda3/envs"
Then if you bring up the command palette (ctl + shift + P
on windows/linux, cmd + shift + P
on mac) and type Python: Select Workspace Interpreter
all your envs will show up and you can select which env to use.
The python extension will also need to be installed for the Select Workspace Interpreter option.
Note: The Select Workspace Interpreter takes around 10 seconds to come up on my computer using the current version of VSCode.