skip to Main Content

I am able to activate the venv in terminal from VSCode in the console using venv/Scripts/activate command.

I can run the python script in the terminal

But when I try to Debug the same script in VSCode, it does not run in the Venv and I get missing dependency errors.

What are the steps to enable the venv when debugging Python in VSCode

The only instructions I can find are using "Python: Select Interpreter" settings

Is this the same as activating the virtual environment?
Do I just point it to venv/Scripts/Python.exe and it will work without activating anything?

2

Answers


  1. When you select an interpreter, VSCode will use the associated environment with all the installed libraries.

    If you’ve already created the virtual environment, you can simply select it using the Python: Select Interpreter command from the Command Palette (⇧⌘P). That will "activate" it, meaning VSCode will use this instead of any other Python installation. If you don’t see it in the list, click on "Enter interpreter path…" and paste the path to the python file in the environment you created.

    More information here.

    Login or Signup to reply.
  2. You can configure the interpreter path using python in launch.json

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Python: Current File",
                "type": "python",
                "request": "launch",
                "program": "${file}",
                "console": "integratedTerminal",
                "justMyCode": true,
                "python": "E:\workspace\python24\.venv\Scripts\python.exe"
            }
        ]
    }
    

    Then start debugging in the Run and Debug panel

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search