microsoft / debugpy

An implementation of the Debug Adapter Protocol for Python
https://pypi.org/project/debugpy/
Other
1.84k stars 137 forks source link

debugger cannot be used #1707

Open StrawberryGZ opened 1 week ago

StrawberryGZ commented 1 week ago

Hi guys,

I don't know why my debugger cannot be used. I tried to changed the python version from the latest one to 2022.4.0 and it still cannot work.

And I followed an instruction to change my launch.json to this:

{
    // 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: 
        //     "type": "python",
        //     "request": "launch",
        //     "program": "${file}",
        //     "console": "integratedTerminal",
        //     "justMyCode": true
        // }    
        {
                "name": "Python", 
                "type": "debugpy",
                "request": "launch",
                "stopOnEntry": false, 
                "python": "D:\\softwares\\anaconda\\python.exe", 
                "program": "${file}",
                "cwd": "${workspaceRoot}",
                "console": "integratedTerminal",
                "justMyCode": true, //只调试自己的Code
                "env": {},
                "envFile": "${workspaceRoot}/.env",
                "redirectOutput": true
        }
    ]
}

vscode Version: 1.94.2 (user setup) python debugger: v2024.12.0 python: v2024.16.1 pylance: v2024.10.1

AND things aren't change, I still cannot use debugger, plsssssssss help!!!

karthiknadig commented 1 week ago

Can you elaborate on what you mean by it does not work? Can you share a video or gif of the issue? Can you also sare the logs from Output > Python Debugger?

Also, try this:

{
    "version": "0.2.0",
    "configurations": [
        {
                "name": "Python", 
                "type": "debugpy",
                "request": "launch",
                "program": "${file}",
                "cwd": "${workspaceRoot}",
                "console": "integratedTerminal",
                "justMyCode": true, //只调试自己的Code
        }
    ]
}
StrawberryGZ commented 1 week ago

Image Image Hi, karthiknadig pls see the attachements, if u need anything pls let me know.

karthiknadig commented 1 week ago

@StrawberryGZ In the video it looks like you have several configurations (green square below) Image

Select the first config then click on the gear icon. See if it opens the correct configuration.

StrawberryGZ commented 1 week ago

Image as u can see, I don't think it is the problem of the configuration

karthiknadig commented 1 week ago

Can you share the logs from Output > Python Debugger?

StrawberryGZ commented 1 week ago

2024-10-18 14:57:06.733 [info] Resolving launch configuration with substituted variables 2024-10-18 14:57:06.742 [info] DAP Server launched with command: d:\softwares\anaconda\python c:\Users\Yanbo.Zhang7.vscode\extensions\ms-python.debugpy-2024.12.0-win32-x64\bundled\libs\debugpy\adapter

python debugger output logs are like this

karthiknadig commented 1 week ago

If you see the screenshot of the logs here: Image

It looks like the extension is submitting the correct adapter path and python. It looks like debugpy is failing to start because you can see the brief moment of the debug session starting.

I suspect either a library shadowing issue or extension corruption.

rchiodo commented 1 week ago

@StrawberryGZ what does the terminal say? Running the debugger should output something in the terminal.

For me it does this:

PS C:\Users\rchiodo\source\testing\test_auto_import>  & 'c:\Users\rchiodo\AppData\Local\Microsoft\WindowsApps\python3.11.exe' 'c:\Users\rchiodo\.vscode-insiders\extensions\ms-python.debugpy-2024.13.2024101501-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher' '62219' '--' 'C:\Users\rchiodo\source\testing\test_auto_import\app\db\test.py' 

That will likely show whatever error is occurring.

karthiknadig commented 1 week ago

@StrawberryGZ You can also try running this from the terminal: d:\softwares\anaconda\python c:\Users\Yanbo.Zhang7\.vscode\extensions\ms-python.debugpy-2024.12.0-win32-x64\bundled\libs\debugpy\adapter

If there is any issue it will throw an error. If there are no issue then it will be blank. You can terminate the process using ctrl+c.

@rchiodo If it fails before the DAP server has the opportunity to start then they might not see the terminal command. The above should indicate if something is failing before it can start the server. If that does not fail, then the next step is to manually launch the DAP server, using the debug server mode, and you can then connect to it from VS Code using debugServer in launch config. This way you can check if the server is starting independent of VS Code. Then launch config will then attach to the DAP server, from that point on it goes through the same process as regular launch. We use this to isolate issue between debugpy and the extension.

StrawberryGZ commented 1 week ago

hi guys, I tried again. and nothing showed up in the terminal output. It seems debugger does not start.

rchiodo commented 1 week ago

Nothing shows up, not even the command?

This:

'c:\Users\rchiodo\AppData\Local\Microsoft\WindowsApps\python3.11.exe' 'c:\Users\rchiodo.vscode-insiders\extensions\ms-python.debugpy-2024.13.2024101501-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher' '62219' '--' 'C:\Users\rchiodo\source\testing\test_auto_import\app\db\test.py'

StrawberryGZ commented 1 week ago

Image

Like this.

rchiodo commented 4 days ago

What happens if you run the command yourself like @karthiknadig asked.

Run this from a terminal:

d:\softwares\anaconda\python c:\Users\Yanbo.Zhang7\.vscode\extensions\ms-python.debugpy-2024.12.0-win32-x64\bundled\libs\debugpy\adapter
StrawberryGZ commented 1 day ago

Image sorry for the late response, it shows like this

rchiodo commented 17 hours ago

Can you follow the directions here and upload the logs? https://github.com/microsoft/debugpy/wiki/Enable-debugger-logs

That should show the commands sent to the debugger and sent back to VS code. I suspect VS code is not getting the commands or is erroring when receiving them.