Repository navigation
Debugger not hitting breakpoint when using a virtual environment #109
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 ~/Projectspython3 -m venv TestVenvcd TestVenvsource bin/activateecho 'print("Hello, world!")' > test.pycode .- Open
test.pyin 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
DonJayamanne commentedon Nov 13, 2017
Please could you provide the sample code used to replicate this with the necessary steps.
Thanks.
DonJayamanne commentedon Nov 13, 2017
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.
DonJayamanne commentedon Nov 13, 2017
Good news, I can replicate this at my end.
DonJayamanne commentedon Nov 13, 2017
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.
DonJayamanne commentedon Nov 13, 2017
From George Bridgeman (@georgebridgeman) on April 28, 2017 19:48
Thanks for the workaround. Looking forward to a fix.
DonJayamanne commentedon Nov 13, 2017
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.
DonJayamanne commentedon Nov 13, 2017
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)
DonJayamanne commentedon Nov 13, 2017
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_dirorvirtualenv env_dirto create a virtual environment.Renamingpyenv. cfgcan't import modules in a virtual environment.Looking forward to repair, think you
DonJayamanne commentedon Nov 13, 2017
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
There is no pyenv.cfg to delete.
Is this a different issue?
4 remaining items
DonJayamanne commentedon Jan 2, 2018
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.
kbakk commentedon Jan 2, 2018
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").DonJayamanne commentedon Jan 2, 2018
Kristoffer Bakkejord (@kbakk) You'll have a file named
pyvenv.cfgin your root directory, please confirm this.The existence of this file causes the debugger not to work correctly.
Note:
launch.json"pythonPath": "${config:python.pythonPath}"settings.json(workspace folder settings)${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.
brettcannon commentedon Mar 12, 2018
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.
jonsagara commentedon Apr 13, 2018
Hi,
I can reproduce this at will. What information do you need from me to help?
Here's my environment:
DonJayamanne commentedon Apr 13, 2018
Jon Sagara (@jonsagara)
Please could you try debugging using the new experimental debugger.
Open your
launch.jsonand change thetypefrompythontopythonExperimental.jonsagara commentedon Apr 13, 2018
That worked! It didn't obey
stopOnEntry, but it did hit a breakpoint that I had set.DonJayamanne commentedon Apr 13, 2018
Thats not yet supported in the experimental debugger.
DerfelKadarn commentedon May 24, 2018
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
brettcannon commentedon 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.