Debugging Conda and Visual Studio Code

The goal is to be able to use the setup of my environment from Conda / Anaconda in the visual studio code debugger. The default pythonpath configuration does not give this effect - rather, this is the path to the default python path (what you get when you type "python" in a new shell).

enter image description here

How do I configure VS code to use the Conda environment?

+5
source share
3 answers

I found the best solution based on the previous ones:

Go to the workplace settings. Override the python.venvPath parameter using the Path to the virtual environment list folder. For the case of anaconda:

Custom setting

This setting allows VS Code to recognize available conda environments . Thus, we can click on the current python interpreter and switch to others:

active conda environment interpreter

+3
source

When I started Visual Studio Code from an activated Conda environment, I was able to use the environment variable to specify the path (MacOS):

 { "python.pythonPath": "~/anaconda/envs/${env.CONDA_DEFAULT_ENV}/bin/python" } 

Go to the Workspace Settings section by pressing Cmd , or by going to the top menu, then add it to settings.json

+2
source

On MacOS, follow these steps:

  • Install Python for VSCode (the most popular extension for python)

  • Go to the Workplace Settings section by pressing Cmd , or go to the top menu.

enter image description here

  1. Add the path to your specific conda environment as shown above to your settings.json file. You can find the paths of your conda environments by typing conda env list in the terminal.

  2. Save and restart VS code

Now the debugger will automatically use this environment! As far as I know, you should do this individually for each project.

For other ways to customize your python path, here is a useful post by the author of the extensions: https://github.com/DonJayamanne/pythonVSCode/wiki/Python-Path-and-Version

+1
source

Source: https://habr.com/ru/post/1267322/


All Articles