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.

Debugging a script run from within a virtual environment's directory does not work

See original GitHub issue

Environment 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:

  1. python3 -m venv test
  2. Open the test folder and change the workspace settings "python.pythonPath": "${workspaceFolder}/bin/python3"
  3. 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.

screen shot 2018-09-07 at 09 54 40

Logs

Output for Python in the Output panel (ViewOutput, 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:closed
  • Created 5 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
brettcannoncommented, Feb 14, 2019

To debug into third-party code (which is anything inside a venv), set "debugStdlib": true in your launch.json. We are going to be getting a better name and improving the support in #2087.

0reactions
OliveITcommented, Jan 23, 2019

I faced the same issue. Any updates?

Read more comments on GitHub >

github_iconTop 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 >

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