6

I'm trying to debug a very simple script in a venv, and the Python debugger just refuses to start working.

The Python extension version is 2019.10.41019 on Windows 10 x64.

The python version is 3.7.1 32-bit.

Debugging without virtual environments works fine. Then I created a venv in C:\TMP\PYENV and added a configuration in launch.json:

{
    "name": "Python: PYENV",
    "type": "python",
    "request": "launch",
    "program": "${file}",
    "console": "integratedTerminal",
    "pythonPath": "C:\\TMP\\PYENV\\Scripts\\python.exe",
},

and start debugging it. Output in terminal:

c:\TMP\PYENV>C:/TMP/PYENV/Scripts/activate.bat
(PYENV) c:\TMP\PYENV>C:\TMP\PYENV\Scripts\python.exe c:\Users\user\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\ptvsd_launcher.py --default --client --host localhost --port 53150 c:\TMP\PYENV\myscript.py

The script starts, all local imports in the venv are found - but all my breakpoints are ignored. The script runs through (and crashes somewhere).

What is missing??

I've searched related questions and most advice to define a config with "python.pythonPath". But this is not valid anymore in the current version. It should be "pythonPath" as in my example above, or the VS Code (or python extension?) complains about invalid name.

1 Answer 1

9

It's because you put your source code within the virtual environment which makes the debugger think it isn't your code but third-party code. Simply move the code out and it will be fine. Alternatively you can set "justMyCode": true in your debugger config and it will then trace through all code and not just what the debugger considers your own code.

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

2 Comments

Brett, thank you a lot! In other replies I've seen advises like "do not put in he venv" but not explained why. I owe you a beer.
@ddbug I don't drink but thanks for the sentiment. :)

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.