Debugging a script run from within a virtual environment's directory does not work
See original GitHub issueEnvironment data
- VS Code version: 1.27.1
- Extension version (available under the Extensions sidebar): Python 2018.8.0
- OS and version: macOS HighSierra 10.13.6
- Python version (& distribution if applicable, e.g. Anaconda): Python 3.7.0
- Type of virtual environment used (N/A | venv | virtualenv | conda | …): venv
- Relevant/affected Python packages and their versions: XXX
Actual behavior
When I set a breakpoint in the venv environment, and click the debug, the runpy.py
file popped up and the program stopped at line 85.
Expected behavior
The program should have stopped at the line where I set the breakpoint.
Steps to reproduce:
python3 -m venv test
- Open the test folder and change the workspace settings
"python.pythonPath": "${workspaceFolder}/bin/python3"
- Then try to write some python code, for example,
a = 1
b = 2
print(a+b)
set a breakpoint at line 2, click the debug, a runpy.py
file popped up and the program stops at line 85: exec(code, run_globals)
, as the following image shows.
Logs
Output for Python
in the Output
panel (View
→Output
, change the drop-down the upper-right of the Output
panel to Python
)
Nothing
Output from Console
under the Developer Tools
panel (toggle Developer Tools on under Help
)
The following statements are executed in the integrated terminal :
[reyshawn:~/Desktop/test]$ cd /Users/reyshawn/Desktop/test ; env "PYTHONIOENCODING=UTF-8" "PYTHONUNBUFFERED=1" "PYTHONPATH=/Users/reyshawn/.vscode/extensions/ms-python.python-2018.8.0/pythonFiles/experimental/ptvsd" /Users/reyshawn/Desktop/test/bin/python3 -m ptvsd --host localhost --port 49846 /Users/reyshawn/Desktop/test/a.py
launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File (Integrated Terminal)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
},
{
"name": "Python: Attach",
"type": "python",
"request": "attach",
"port": 5678,
"host": "localhost"
},
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"console": "integratedTerminal",
"args": [
"runserver",
"--noreload",
"--nothreading"
],
"django": true
},
{
"name": "Python: Flask",
"type": "python",
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "app.py"
},
"args": [
"run",
"--no-debugger",
"--no-reload"
],
"jinja": true
},
{
"name": "Python: Current File (External Terminal)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "externalTerminal"
}
]
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Running python script from inside virtualenv bin is not working
In a nutshell, virtualenv modifies your shell environment so that Python will look in different areas to find modules you want to import....
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 >Using Python environments in VS Code
A virtual environment is a folder that contains a copy (or symlink) of a specific interpreter. When you install into a virtual environment,...
Read more >Setting up a Development environment — OctoPrint master ...
Create a virtual environment in the checked out source folder to use for ... Creating virtual environments avoids potential versioning issues for the ......
Read more >Environment — Explore Flask 1.0 documentation
You only interact with it directly when activating the virtual environment and it shouldn't be in version control, so there's no need to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
To debug into third-party code (which is anything inside a venv), set
"debugStdlib": true
in yourlaunch.json
. We are going to be getting a better name and improving the support in #2087.I faced the same issue. Any updates?