mfussenegger / nvim-dap-python

An extension for nvim-dap, providing default configurations for python and methods to debug individual test methods or classes.
GNU General Public License v3.0
490 stars 46 forks source link

Python quit unexpectedly when terminating DAP UI #151

Open Chamal1120 opened 1 week ago

Chamal1120 commented 1 week ago

I have an issue where macOS gives this error message "Python quit unexpectedly" on every time when I try to terminate, exit or reach the end of the program that I'm debugging. Apart from that the debugger works as expected.

OS - macOS Monterey 12.7.5 (intel macbook) Package manager - homebrew (python also installed with brew) neovim version - v0.10.0 (installed with brew) Plugin manager - lazy.nvim **Debugpy installed with mason tho. (actually I don't how it works. I just copy pasted some codes.)

Screen Shot 2024-06-26 at 11 11 15 PM

below is my lua code related to debugging plugins located inside parent folder > lua > plugins

return {
  {
      "williamboman/mason.nvim",
      config = function()
          require("mason").setup()
      end,
  },
  {
      "jay-babu/mason-nvim-dap.nvim",
      config = function()
          require("mason-nvim-dap").setup({
              ensure_installed = { "python" },
              automatic_installation = false, 
              handlers = {
                  -- Custom handlers for specific adapters can be defined here
                  python = function(config)
                      config.adapters = {
                          type = "executable",
                          command = vim.fn.stdpath("data") .. "/mason/packages/debugpy/venv/bin/python",
                          args = { "-m", "debugpy.adapter" },
                      }
                      require('mason-nvim-dap').default_setup(config)
                  end,
              },
          })
      end,
  },
  {
      "mfussenegger/nvim-dap",
      dependencies = {
          "rcarriga/nvim-dap-ui",
          "nvim-neotest/nvim-nio",
          "mfussenegger/nvim-dap-python",
      },
      config = function()
          local dap = require("dap")
          local dapui = require("dapui")

          require("dapui").setup()
          require("dap-python").setup()

          dap.listeners.before.attach.dapui_config = function()
              dapui.open()
          end
          dap.listeners.before.launch.dapui_config = function()
              dapui.open()
          end
          dap.listeners.before.event_terminated.dapui_config = function()
              dapui.close()
          end
          dap.listeners.before.event_exited.dapui_config = function()
              dapui.close()
          end

          vim.keymap.set("n", "<Leader>dt", function() dap.toggle_breakpoint() end, {})
          vim.keymap.set("n", "<Leader>dc", function() dap.continue() end, {})
      end,
  },
}

p.s. - I'm a total beginner to neovim and lua and I might have made a lot of mistakes. I hope someone would help me out to correct my code.

BLACKSWORD0 commented 1 week ago

If I use the python from homebrew, I get the same message in the same condition. If I use the python from anaconda, it will not show the message. My system is macOS 14.5(M1). I use a plugin called venv-selector to change environment.

Chamal1120 commented 1 week ago

If I use the python from homebrew, I get the same message in the same condition. If I use the python from anaconda, it will not show the message. My system is macOS 14.5(M1). I use a plugin called venv-selector to change environment.

@BLACKSWORD0 can you tell me more about your conda setup?

  1. Can I use it alongside my macos default python + hombrew python?
  2. did you installed conda from brew? (if so what is the exact brew command?)
  3. How do I set the path for the debugpy in my lua plugin with conda?
BLACKSWORD0 commented 1 week ago

If I use the python from homebrew, I get the same message in the same condition. If I use the python from anaconda, it will not show the message. My system is macOS 14.5(M1). I use a plugin called venv-selector to change environment.

@BLACKSWORD0 can you tell me more about your conda setup?

  1. Can I use it alongside my macos default python + hombrew python?
  2. did you installed conda from brew? (if so what is the exact brew command?)
  3. How do I set the path for the debugpy in my lua plugin with conda?
  1. Yes, we can use different python virtual environment, so we can use anaconda alongside homebrew python. But I don't use macOS default python.
  2. Yes, I install cask anaconda from homebrew.( brew install --cask anaconda).
  3. I use a plugin called venv-selector to change environment. You can view its doc for more details. My config about them is following (My full config of python bases on astronvim, so I just show this part.):

    
    {
    "linux-cultist/venv-selector.nvim",
    dependencies = {
      "nvim-telescope/telescope.nvim",
      "mfussenegger/nvim-dap-python",
      "nvim-lua/plenary.nvim",
    },
    opts = {
      anaconda_base_path = "/opt/homebrew/anaconda3",
      anaconda_envs_path = "/opt/homebrew/anaconda3/envs",
      stay_on_this_version = true,
      dap_enabled = true,
      settings = {
        options = {
          notify_user_on_venv_activation = true,
        },
      },
    },
    cmd = { "VenvSelect" },
    },
    
    {
    "mfussenegger/nvim-dap-python",
    dependencies = "mfussenegger/nvim-dap",
    ft = "python",
    config = function(_, opts)
      require("dap-python").setup("python", opts)
    end,
    },

But I don't use debugpy in mason, I just install debugpy in ~/.virtualenvs.  "venv-selector" will find it automatically.  If you want, you can change the config of  "venv-selector" to find debugpy in mason.
The following is an example to show  "venv-selector":

https://github.com/mfussenegger/nvim-dap-python/assets/56479341/825ea27a-f090-44bf-b28c-57b56b7de48a
Chamal1120 commented 6 days ago

@BLACKSWORD0 Thanks will look into this and give you an update.