I've been trying to get dap working with python in Spacemacs for a week. I'm trying to start using Spacemacs as my main Python IDE, I should mention I'm new to emacs and spacemacs, I could be missing a step that you think is obvious.

In my .spacemacs file, under dotspacemacs-configuration-layer, I've included auto-completion, lsp, python, and dap (all without any special configurations, I'm just using the defaults). Everything works except for dap so far, for example I can execute my code, and auto-completion works great.

But, when I try to debug a python file (by running SPC d d d, then selecting Python :: Run file (buffer)) I get some complex error message, here is the full output:

-*- mode: dap-server-log; default-directory: "~/Desktop/scratch/" -*-
Debug Adapter started at Sun Jun 12 09:51:56

/usr/bin/python -m ptvsd --wait --host localhost --port 34639 trash.py
Traceback (most recent call last):
  File "/home/otooleat/.local/lib/python3.10/site-packages/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py", line 283, in _on_run
    self.process_net_command_json(self.global_debugger_holder.global_dbg, json_contents)
  File "/home/otooleat/.local/lib/python3.10/site-packages/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_process_net_command_json.py", line 164, in process_net_command_json
    cmd = on_request(py_db, request)
  File "/home/otooleat/.local/lib/python3.10/site-packages/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_process_net_command_json.py", line 623, in on_stacktrace_request
    self.api.request_stack(py_db, request.seq, thread_id, fmt=fmt, start_frame=start_frame, levels=levels)
  File "/home/otooleat/.local/lib/python3.10/site-packages/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_api.py", line 190, in request_stack
    if internal_get_thread_stack.can_be_executed_by(get_current_thread_id(threading.current_thread())):
  File "/home/otooleat/.local/lib/python3.10/site-packages/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py", line 595, in can_be_executed_by
    self._cmd = py_db.cmd_factory.make_get_thread_stack_message(
  File "/home/otooleat/.local/lib/python3.10/site-packages/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_net_command_factory_json.py", line 238, in make_get_thread_stack_message
    end = min(start + levels, total_frames)
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

Debug Adapter finished at Sun Jun 12 09:51:57

... I have no idea how to interpret that. I've been reading everything I can read, but the different levels of integration (dap + emacs + spacemacs) is making it difficult to learn about the problem.

I've installed ptvsd using pip install "ptvsd>=4.2", my understanding is that as long as that is installed, and I include dap and lsp in my .spacemacs file, it should just work. Am I missing something dumb? I have a feeling I haven't installed a required package or I'm not starting the debugger correctly. For example am I suppose to edit that Python :: Run file (buffer) debug configuration template or something? Or should that work out of the box? I'm also assuming that pressing SPC d d d while my active buffer is a python file is enough for the system to realize that I want it to debug that python file, is that correct?

Any help would be appreciated, I'm really loving Spacemacs so far and would love to be able to use it as my main IDE.

1 Answer 1


With help from the spacemacs gitter room I was able to get it working. Here is the solution:

  1. Spacemacs doesn't use ptvsd anymore and uses debugpy instead, so I did this:

    pip uninstall ptvsd

    pip install debugpy

  2. Then you need to tell spacemacs that you want to use debugpy by changing "dap-python-debugger" from ptvsd to debugpy in the dap-python.el file.

Now, that should be all you need to do, so test that it works. But if the error shows up again it is because this commit needs to be applied to a file in debugpy (it may already be applied by the time you read this): https://github.com/microsoft/debugpy/commit/78b030f5092d91df64860914962333e89852ea9b

  • Thanks for pointing to the commit with the fix! While the fix in debugpy is not available in the latest release 1.6.0, I used the development branch pip install git+https://github.com/microsoft/debugpy and it fixed the issue.
    – Curious
    Jul 5, 2022 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.