question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Debugger not hitting breakpoint when using a virtual environment

See original GitHub issue

From @georgebridgeman on April 24, 2017 21:13

I cannot get the debugger to stop at breakpoints when my project is using a virtual environment created using the Python venv module.

I have tried specifying the absolute path to Python in the pythonPath property in launch.json and launching VS Code from the command line, as suggested in issues #91 and #148 but still cannot get it to work.

The code in this example (a simple print statement) debugs fine when a project is not created in a venv.

Environment data

VS Code version: 1.11.2 Python Extension version: 0.6.3 Python Version: 3.6.0 OS and version: MacOS X 10.11.6

Actual behavior

Debugger runs and output is written to Debug Console, but breakpoints are not hit.

Expected behavior

Debugger should break on breakpoints.

Steps to reproduce:

  • cd ~/Projects
  • python3 -m venv TestVenv
  • cd TestVenv
  • source bin/activate
  • echo 'print("Hello, world!")' > test.py
  • code .
  • Open test.py in the editor
  • Apply attached launch.json with absolute path to Python
  • Switch back to test.py, add a breakpoint to line 1 and run debugger using F5
  • Observe the output in Debug Console despite the breakpoint having no effect

Settings

Your launch.json (if dealing with debugger issues):

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python",
            "type": "python",
            "request": "launch",
            "stopOnEntry": true,
            "pythonPath": "/Users/george/Projects/TestVenv/bin/python",
            "program": "${file}",
            "cwd": "${workspaceRoot}",
            "env": {},
            "envFile": "${workspaceRoot}/.env",
            "debugOptions": [
                "WaitOnAbnormalExit",
                "WaitOnNormalExit",
                "RedirectOutput"
            ]
        }
    ]
}

Your settings.json:
No settings.json file in the project.

Logs

Output from Python output panel

----------Generating Tags----------
ctags --options=/Users/george/.vscode/extensions/donjayamanne.python-0.6.3/resources/ctagOptions --languages=Python --exclude=**/site-packages/** -o /Users/george/Projects/TestVenv/.vscode/tags .
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ctags: illegal option -- -
usage: ctags [-BFadtuwvx] [-f tagsfile] file ...

Output from Console window (Help->Developer Tools menu)

shell.ts:475TypeError: Cannot read property 'Threads' of null
    at PythonDebugger.threadsRequest (/Users/george/.vscode/extensions/donjayamanne.python-0.6.3/out/client/debugger/Main.js:340:27)
    at PythonDebugger.DebugSession.dispatchRequest (/Users/george/.vscode/extensions/donjayamanne.python-0.6.3/node_modules/vscode-debugadapter/lib/debugSession.js:427:22)
    at PythonDebugger.ProtocolServer._handleData (/Users/george/.vscode/extensions/donjayamanne.python-0.6.3/node_modules/vscode-debugadapter/lib/protocol.js:104:38)
    at Socket.<anonymous> (/Users/george/.vscode/extensions/donjayamanne.python-0.6.3/node_modules/vscode-debugadapter/lib/protocol.js:24:60)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at Pipe.onread (net.js:543:20): Error: TypeError: Cannot read property 'Threads' of null
    at PythonDebugger.threadsRequest (/Users/george/.vscode/extensions/donjayamanne.python-0.6.3/out/client/debugger/Main.js:340:27)
    at PythonDebugger.DebugSession.dispatchRequest (/Users/george/.vscode/extensions/donjayamanne.python-0.6.3/node_modules/vscode-debugadapter/lib/debugSession.js:427:22)
    at PythonDebugger.ProtocolServer._handleData (/Users/george/.vscode/extensions/donjayamanne.python-0.6.3/node_modules/vscode-debugadapter/lib/protocol.js:104:38)
    at Socket.<anonymous> (/Users/george/.vscode/extensions/donjayamanne.python-0.6.3/node_modules/vscode-debugadapter/lib/protocol.js:24:60)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at Pipe.onread (net.js:543:20)
    at file:////Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/electron-browser/workbench.main.js:28:2160295
    at Object.v [as _notify] (file:////Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/electron-browser/workbench.main.js:28:50893)
    at Object.enter (file:////Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/electron-browser/workbench.main.js:28:54394)
    at _run (file:////Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/electron-browser/workbench.main.js:28:55715)
    at _error (file:////Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/electron-browser/workbench.main.js:28:55232)
    at file:////Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/electron-browser/workbench.main.js:28:1911266
    at g.e.dispatch (file:////Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/electron-browser/workbench.main.js:28:1912617)
    at g.e.handleData (file:////Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/electron-browser/workbench.main.js:28:1912125)
    at Socket.<anonymous> (file:////Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/electron-browser/workbench.main.js:28:1911126)
    at emitOne (events.js:96:13)

Copied from original issue: DonJayamanne/pythonVSCode#913

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:20 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
DonJayamannecommented, Apr 13, 2018

@jonsagara Please could you try debugging using the new experimental debugger. Open your launch.json and change the type from python to pythonExperimental.

0reactions
brettcannoncommented, May 24, 2018

@DerfelKadarn since we’re not switching the experimental debugger to be the default one until we’re happy with its stability we don’t have an ETA.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Debugger Not Stopping at Breakpoints in VS Code for Python
In my case, coverage was setup in my setup.cfg file. It worked by either removing it from that file or using Tomasz's "env"...
Read more >
VS Code Debugger not working for python - Microsoft Q&A
I am experiencing debugging issue for my VS Code in WIN-10. It happened since weekend when I did OS restart . It was...
Read more >
VSCode: debugging code located in Python virtual environment
In trying to set up a virtual environment(virtualenv) for Python to be used in VSCode, I encountered a situation where I was unable...
Read more >
Debug your app - Android Developers
The Android virtual machine guarantees that any object the debugger is aware of is ... Android Studio does not pause your app when...
Read more >
Run and Debug Java in Visual Studio Code
You can also use the user setting java.debug.settings.console to configure a global console for all Java debug sessions. Breakpoints. The Debugger for Java ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found