How can I debug a python code in a virtual environment using VSCode?

Make sure the environment you want to use is selected in the Python extension for VS Code by running the Select Interpreter command or via the status bar. Otherwise you can explicitly set the Python interpreter to be used when debugging via the python setting for your debug config.


Use the Python: Select Interpreter command from the Command Palette (Ctrl+Shift+P) and select the python interpreter that belongs to the new virtual environment.

If you are using a virtual env on linux on the drop down, select env>bin>python i.e env/bin/python