Skip to content

Debugger not hitting breakpoint when using a virtual environment #109

Closed

Description

From George Bridgeman (@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

Activity

  1. DonJayamanne commented on Nov 13, 2017

    @DonJayamanne
    Author

    Please could you provide the sample code used to replicate this with the necessary steps.
    Thanks.

  2. DonJayamanne commented on Nov 13, 2017

    @DonJayamanne
    Author

    From George Bridgeman (@georgebridgeman) on April 25, 2017 9:7

    I've gone through the steps to reproduce above, and pushed the resulting project here:
    https://github.com/georgebridgeman/TestVenv

    Hope this helps. Let me know if you need anything else.

  3. DonJayamanne commented on Nov 13, 2017

    @DonJayamanne
    Author

    Good news, I can replicate this at my end.

  4. DonJayamanne commented on Nov 13, 2017

    @DonJayamanne
    Author

    For now please delete or rename the pyenv.cfg.
    For some reason the presense of the pyenv.cfg (even if empty) is not letting the debugger debug the python code.
    Will look into this later.

  5. DonJayamanne commented on Nov 13, 2017

    @DonJayamanne
    Author

    From George Bridgeman (@georgebridgeman) on April 28, 2017 19:48

    Thanks for the workaround. Looking forward to a fix.

  6. DonJayamanne commented on Nov 13, 2017

    @DonJayamanne
    Author

    From edliang765 on June 5, 2017 17:40

    Same problem here.

    My environment is :
    VS Code version: 1.12.2
    Python Extension version: 0.6.4
    Python Version: 3.6.1
    OS and version: MS Windows 10 Version 1703

    The workaround works for me too. Hope a fix will be out soon.

  7. DonJayamanne commented on Nov 13, 2017

    @DonJayamanne
    Author

    From @hellbago on July 3, 2017 8:31

    The solution of renaming pyvenv.cfg works for me, but then I have an import error with a module that i have installed in my virtual environment (warpctc_pytorch). Is there another possible workaround? Don Jayamanne (@DonJayamanne)

  8. DonJayamanne commented on Nov 13, 2017

    @DonJayamanne
    Author

    From aaazz47 on October 10, 2017 2:52

    @hellbago Don Jayamanne (@DonJayamanne)
    I have the same problem:
    The debugger is not working in a virtual environment whether it is using python-m venv env_dir or virtualenv env_dir to create a virtual environment.Renaming pyenv. cfg can't import modules in a virtual environment.
    Looking forward to repair, think you

  9. DonJayamanne commented on Nov 13, 2017

    @DonJayamanne
    Author

    From Moseudi (@kostya2c) on November 6, 2017 0:33

    I have similar problem (debugger not stopping on a breakpoints) with Python 2.7 and virtualenv.
    The VS Code exception is

    [uncaught exception]: Error: TypeError: Cannot read property 'Threads' of undefined
        at PythonDebugger.threadsRequest
    ...
    

    There is no pyenv.cfg to delete.
    Is this a different issue?

  10. 4 remaining items

  11. DonJayamanne commented on Jan 2, 2018

    @DonJayamanne
    Author

    Kristoffer Bakkejord (@kbakk) Please could you test this with the latest version of the Python Extension. The issue you are facing may have be resolved. I say this because the errors you're getting in your console window are related to another issue that was resolved in the December release.

  12. kbakk commented on Jan 2, 2018

    @kbakk

    Don Jayamanne (@DonJayamanne) I performed the steps on Python extension Version 0.9.1 (19 December 2017), VS Code: 1.19.1, unfortunately, am I still able to reproduce this issue following the above steps (it works when I change to "pythonPath": "${workspaceRoot}/venv/Scripts/python.exe").

  13. DonJayamanne commented on Jan 2, 2018

    @DonJayamanne
    Author

    Kristoffer Bakkejord (@kbakk) You'll have a file named pyvenv.cfg in your root directory, please confirm this.
    The existence of this file causes the debugger not to work correctly.

    Note:

    • There's no need to change the paths in launch.json
    • Always leave the path as as "pythonPath": "${config:python.pythonPath}"
    • If you want to change the path, then do so in settings.json (workspace folder settings)
    • Don't use ${workspaceRoot}, that variable has been deprecated, use ${workspaceFolder} instead.

    Once again, debugging with `pyvenv.cfg in the root directory some how interferes with the debugger. We'll be looking into that separately.

  14. brettcannon commented on Mar 12, 2018

    @brettcannon
    Member

    It has been over a month since more info was requested so I am closing this issue. If you find the time to provide the requested details then we would be happy re-open this issue.

  15. jonsagara commented on Apr 13, 2018

    @jonsagara

    Hi,

    I can reproduce this at will. What information do you need from me to help?

    Here's my environment:

    • macOS High Sierra 10.13.4
    • python 3.6.5, installed via homebrew
    • Visual Studio Code 1.22.2
    • Python (ms-python.python) 2018.3.1
  16. DonJayamanne commented on Apr 13, 2018

    @DonJayamanne
    Author

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

  17. jonsagara commented on Apr 13, 2018

    @jonsagara

    That worked! It didn't obey stopOnEntry, but it did hit a breakpoint that I had set.

  18. DonJayamanne commented on Apr 13, 2018

    @DonJayamanne
    Author

    That worked! It didn't obey stopOnEntry

    Thats not yet supported in the experimental debugger.

  19. DerfelKadarn commented on May 24, 2018

    @DerfelKadarn

    This solved my problem. Any idea when pythonExperimental will be released? This is the only way to make it stop at breakpoints. Any known issue we should be aware of?

    Thanks

  20. brettcannon commented on May 24, 2018

    @brettcannon
    Member

    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.

  21. locked as resolved and limited conversation to collaborators on Jul 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-debuggingbugIssue identified by VS Code Team member as probable buginfo-neededIssue requires more information from poster

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions