How does your adapter definition look like? debugpy is a bit special in regards to the attach handling. For most adapters you still launch the debug-adapter the same way, and then the debug-adapter attaches to the process. For debugpy the process using debugpy.listen() (or when using python -m debugpy --listen ...) launches the service that speaks DAP.
Because of that you'll need to switch over to a adapter definition of type server. I'd recommend to use nvim-dap-python which does that:
https://github.com/mfussenegger/nvim-dap-python/blob/d4400d075c21ed8fb8e8ac6a5ff56f58f6e93531/lua/dap-python.lua#L130-L153
Attach to debugpy
debugpy.nvim: Command and API frontend to nvim-dap and Debugpy (debugging Python)
Debugpy + Nvim-DAP in a Docker container - help getting this to work?
debugging - Configuring nvim-dap for JavaScript and Python - Stack Overflow
Videos
Hi there,
I use Python quite a lot and when I debug the code I want to be able to quickly specify what I want to debug and not have to manually create individual debugger configurations for each project. So I made a plugin that does it for you: debugpy.nvim (GitHub mirror). It provides a thin layer on top of nvim-dap.
I am a very big fan of the way nvim-dap is structured: it is basically just a Lua library with a reasonable minimum of UI, and it is really easy to build plugins on top of that. Debugpy.nvim provides a new command :Debugpy which allows you to specify a sub-command (currently module, program or attach) and arguments, and it will launch the debugger for you. Example:
" Debug a module with command-line arguments Debugpy module main foo bar " Attach to a running process Debugpy attach 127.0.0.1 5678
Even if you don't like the command you can still use the API, which supports Lua and Vim script:
local debugpy = require 'debugpy'
local config = debugpy.configure('module', 'main', 'foo', 'bar')
debugpy.run(config)You can define your own sub-commands and override the run function to alter how the debugger is started or to inject your own debugger settings. No setup function or other nonsense, just pure Lua and Vim script:
-- Your personal default settings
default = { justMyCode = false }
-- Implementation which injects your default settings
require('debugpy').run = function(config)
local final = vim.tbl_extend('keep', config, default)
require('dap').run(final)
endI have been using this for a couple of months in my configuration, and now I have turned it into a proper plugin. I hope you enjoy it as well. And hey, it even comes with an actual manual! (sorry, I just had to make that jab)
I have just created video about how I solved problem with debugger for Python and make it working. It is simple and I show everything here https://www.youtube.com/watch?v=8urgm9LZI08
But basically, you need to add couple of plugins into init.lua, then call setup() function to set default values, then create few shortcuts for opening dapui and install also debugpy.
Here are data from my init.lua
install plugins
--DAP debugger
{ 'mfussenegger/nvim-dap' },
{ 'theHamsta/nvim-dap-virtual-text' },
{ 'nvim-neotest/nvim-nio' },
{ 'rcarriga/nvim-dap-ui' },
{ 'mfussenegger/nvim-dap-python'},
-- debugger end
call setup functions
require('dap-python').setup()
require('dapui').setup()
install also debugpy
and shortcuts
vim.api.nvim_set_keymap("n", "<leader>db", ":DapToggleBreakpoint<CR>", {noremap=true})
vim.api.nvim_set_keymap("n", "<leader>dc", ":DapContinue<CR>", {noremap=true})
vim.api.nvim_set_keymap('n', '<leader>do', ':lua require("dapui").open()<CR>', { noremap = true, silent = true })
So your problem is cause you are missing that setup() call for require('dap-python').setup() require('dapui').setup()
Check this and I hope this will help you. Also all is on my video as well.
My Config DAP Javascript
{ "rcarriga/nvim-dap-ui", lazy = true, event = "BufRead", dependencies = { { "mfussenegger/nvim-dap", lazy = true }, { "nvim-neotest/nvim-nio", lazy = true }, { "mxsdev/nvim-dap-vscode-js", dependencies = { "microsoft/vscode-js-debug", version = "1.x", build = "npm i && npm run compile vsDebugServerBundle && mv dist out", }, config = function() require("dap-vscode-js").setup({ -- node_path = "node", -- Path of node executable. Defaults to $NODE_PATH, and then "node" debugger_path = vim.fn.stdpath("data") .. "/lazy/vscode-js-debug", -- debugger_cmd = { "extension" }, -- Command to use to launch the debug server. Takes precedence over `node_path` and `debugger_path`. adapters = { "chrome", "pwa-node", "pwa-chrome", "pwa-msedge", "node-terminal", "pwa-extensionHost", "node", "chrome", }, -- which adapters to register in nvim-dap -- log_file_path = "(stdpath cache)/dap_vscode_js.log" -- Path for file logging -- log_file_level = false -- Logging level for output to file. Set to false to disable file logging. -- log_console_level = vim.log.levels.ERROR -- Logging level for output to console. Set to false to disable console output. }) end, }, }, config = function() require("user.dapui") local js_based_languages = { "typescript", "javascript", "typescriptreact" } for _, language in ipairs(js_based_languages) do require("dap").configurations[language] = { { type = "pwa-node", request = "launch", name = "Launch file", program = "${file}", cwd = "${workspaceFolder}", }, { type = "pwa-node", request = "attach", name = "Attach", processId = require("dap.utils").pick_process, cwd = "${workspaceFolder}", }, { type = "pwa-chrome", request = "launch", name = 'Start Chrome with "localhost"', url = "http://localhost:3000", webRoot = "${workspaceFolder}", userDataDir = "${workspaceFolder}/.vscode/vscode-chrome-debug-userdatadir", }, } end end, keys = { { "<leader>d", "", desc = " Debug" }, { "<leader>dt", "<cmd>lua require'dap'.toggle_breakpoint()<cr>", desc = "Toggle Breakpoint" }, { "<leader>db", "<cmd>lua require'dap'.step_back()<cr>", desc = "Step Back" }, { "<leader>dc", "<cmd>lua require'dap'.continue()<cr>", desc = "Continue" }, { "<leader>dC", "<cmd>lua require'dap'.run_to_cursor()<cr>", desc = "Run To Cursor" }, { "<leader>dd", "<cmd>lua require'dap'.disconnect()<cr>", desc = "Disconnect" }, { "<leader>dg", "<cmd>lua require'dap'.session()<cr>", desc = "Get Session" }, { "<leader>di", "<cmd>lua require'dap'.step_into()<cr>", desc = "Step Into" }, { "<leader>do", "<cmd>lua require'dap'.step_over()<cr>", desc = "Step Over" }, { "<leader>du", "<cmd>lua require'dap'.step_out()<cr>", desc = "Step Out" }, { "<leader>dp", "<cmd>lua require'dap'.pause()<cr>", desc = "Pause" }, { "<leader>dr", "<cmd>lua require'dap'.repl.toggle()<cr>", desc = "Toggle Repl" }, { "<leader>ds", "<cmd>lua require'dap'.continue()<cr>", desc = "Start" }, { "<leader>dq", "<cmd>lua require'dap'.close()<cr>", desc = "Quit" }, { "<leader>dU", "<cmd>lua require'dapui'.toggle({reset = true})<cr>", desc = "Toggle UI" }, },},}For Python use mason-nvim-dap
I use lazyvim, after enable dap.core and lang.python in :LazyExtras, still can't debug python file.
after start debug, will pop a window, show following text
Content-Length: 137
{"seq": 1, "type": "event", "event": "output", "body": {"category": "telemetry", "output": "ptvsd", "data": {"packageVersion": "1.8.0"}}}Content-Length: 139
{"seq": 2, "type": "event", "event": "output", "body": {"category": "telemetry", "output": "debugpy", "data": {"packageVersion": "1.8.0"}}}I search the same problem in github, others also have the problem, but no answers
https://github.com/LazyVim/LazyVim/issues/1284
https://github.com/mfussenegger/nvim-dap-python/issues/118