1

OS:Windows10Pro

IDE:VScode Ver1.59.0

Python:Ver 3.9.6

I created a virtual environment with venv and selected python.exe on the virtual environment with "select interpreter". Even if I specify a breakpoint on a simple script and execute debug (F5), the breakpoint will be ignored and executed.

In Ubuntu 20.04 on VMware, I debugged in the same way using VScode Ver1.59.0, so it will stop at the breakpoint.

In both Windows and Ubuntu, I didn't specify the path in launch.json or setting.json.

I specified the Python path in launch.json on Windows, but the debugger doesn't work.

Is this a bug specific to the Windows environment? Or am I forgetting to set something?


1.python -m venv [ENV_NAME]

2.Open Folder [ENV_NAME] on VScode

3.Open Terminal

4../Script/activate

5.create python script

a=0
print(a) #<-set berak point

6.select interpreter -> ./Script/python.exe

7.press F5(run debug)

5
  • if you open the folder with the virt env and select that environment the launch should activate the environment for you, if not restart VSC, it should work if the interpreter setting is not changed in the session Commented Aug 20, 2021 at 1:06
  • I made sure the python interpreter on my VENV is running. I pip install / uninsatall the requests package and see if import requests raises an error. I think the debugger isn't working.I made sure the python interpreter on my VENV is running. I think the debugger isn't working. I don't know when this happened from the VScode version, but in the past the debugger worked this way. Commented Aug 20, 2021 at 1:37
  • I wonder why you open venv as root_project in VS Code? Can you please try opening the folder with .py file then select venv as python interpreter? Create launch.json with default configurations then start debugging. see if it stops at the breakpoint. Commented Aug 20, 2021 at 2:25
  • It seems I didn't understand. The cause was that the venv folder was the project folder. I made the venv folder a subfolder of the project folder and the debugger worked. Commented Aug 20, 2021 at 2:39
  • If you open venv as root_project which is also current working directory for VS Code and .py isn't in it, the launch.json won't work because it's only effective for current project. When you open the project as current working directory, even though you use the venv in other folders as interpreter, debug works as the .py file is in his effective scope: current workspace. Commented Aug 20, 2021 at 2:57

1 Answer 1

3

I didn't understand that VScode on Windows had to create an ENV folder directly under the workspace folder.

Curiously, on Ubuntu, the debugger works even if the ENV folder is a workspace folder.


1.Create a project folder

2.Open project folder on VScode

3.Open Terminal

4.cd project folder

5.create venv (python -m venv [ENV_NAME])

6../[ENV_NAME]/Script/acitivate

7.create python script

8.select interpreter -> ./[ENV_NAME]/Script/python.exe

9.press F5(run dubug)

Sign up to request clarification or add additional context in comments.

2 Comments

for step 8, do you mean to type the command after "->" in terminal OR to set the interpreter in setting ? If it's the latter case, may you please kindly tell how to go to that setting page ?
Grace, I found out how to do this. In VS Code, press Ctrl+Shift+P and select "Python: Select Interpreter", then select the python.exe in your virtual environment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.