I'm using vscode in Windows 10 as my code editor, and want to make an easy way to launch it with the correct conda env to allow debugging.
Currently I am having to open a command prompt, then activate the conda env, then paste the shortcut to vscode into the prompt to execute. Like so:
cmd
activate env-name
"C:\Program Files (x86)\Microsoft VS Code\Code.exe"
I have tried creating a batch file to wrap these calls, but unfortunately once I call "source activate" to start the conda env, the batch commands after this are not executed as it is considered another instance.
Any tips? Other than writing a vscode extension to handle this (which I'm seriously tempted to do, but it's such a simple problem...)
The best option I found is to set the
python.venvPath
parameter in vscode settings to your anaconda envs folder.Then if you bring up the command palette (
ctl + shift + P
on windows/linux,cmd + shift + P
on mac) and typePython: 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. My answer was originally posted here.
Using Conda 4.7.5, I was able to change the Target under the VsCode taskbar shortcut Properties from:
"C:\Users\Paul.siersma\AppData\Local\Programs\Microsoft VS Code\Code.exe"
To:
C:\Users\Paul.siersma\Anaconda3\_conda.exe run -p C:\Users\Paul.siersma\Anaconda3 "C:\Users\Paul.siersma\AppData\Local\Programs\Microsoft VS Code\Code.exe"
This uses the
run
command (marked experimental) and starts VSCode using the base Conda environment. You could specify another environment by changing the-p
flag to the environment location eg-p [..]\Anaconda3\envs\myenv
You might want to run
source activate env-name
as a task in visual studio. https://code.visualstudio.com/Docs/editor/taskstasks.json