Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Visual Studio Code to debug Django app in a virtualenv?

I would like to have possibility to do a debugging of Django application in Visual Studio Code. I have a virtualenv, made a change in launch.json file that look like this:

{
    "name": "Django",
    "type": "python",
    "request": "launch",
    "stopOnEntry": true,
    "pythonPath": "${workspaceRoot}/.venv/bin/python2.7",
    "program": "${workspaceRoot}/mysite/manage.py",
    "args": [
        "runserver"
    ],
    "debugOptions": [
        "WaitOnAbnormalExit",
        "WaitOnNormalExit",
        "DjangoDebugging",
        "RedirectOutput"
    ]
},

put several break points in the code and run it. Unfortunately, the execution is not stopped on the line with break points. I tried the same without virtualenv and everything worked perfectly.

Please, point out what I am doing wrong here.

like image 907
Stanislav Hordiyenko Avatar asked Sep 13 '16 01:09

Stanislav Hordiyenko


2 Answers

1) Press CTRL + ,
2) Select Workspace Settings
3) Add the following line in the settings file opened.

"python.pythonPath": "path_to_your_env"


You're done!

like image 165
Paulo Fabrício Avatar answered Sep 24 '22 20:09

Paulo Fabrício


For me, the following 2 changes worked

  1. Add an absolute path for pythonPath
  2. Use the "--noreload" option while starting the project

Here's the relevant part of my config

    {
        "name": "Django",
        "type": "python",
        "request": "launch",
        "stopOnEntry": true,
        "pythonPath": "/Users/xyz/Documents/dev/my_project/my_project_env/bin/python",
        "program": "${workspaceRoot}/manage.py",
        "args": [
            "runserver",
            "0.0.0.0:8080",
            "--noreload"                
        ],
        "debugOptions": [
            "WaitOnAbnormalExit",
            "WaitOnNormalExit",
            "RedirectOutput",
            "DjangoDebugging"
        ]
    },
like image 28
Sudhi Pulla Avatar answered Sep 25 '22 20:09

Sudhi Pulla