Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python quit unexpectedly when terminating DAP UI #151

Open
Chamal1120 opened this issue Jun 26, 2024 · 6 comments
Open

Python quit unexpectedly when terminating DAP UI #151

Chamal1120 opened this issue Jun 26, 2024 · 6 comments

Comments

@Chamal1120
Copy link

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
Copy link

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
Copy link
Author

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
Copy link

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":

test.mp4

@Chamal1120
Copy link
Author

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

@danischn
Copy link

I have the exact same issue, i use python 3.12.4.

This is my setup for nvim dap.

return {
	{
		"mfussenegger/nvim-dap",
		-- stylua: ignore
		keys = {
      { "<leader>s", function() require("dap").continue() end, desc = "Debug: Continue" },
      { "<up>", function() require("dap").step_over() end, desc = "Debug: Step over" },
      { "<down>", function() require("dap").step_into() end, desc = "Debug: Step into" },
      { "<right>", function() require("dap").step_out() end, desc = "Debug: Step out" },
      { "<leader>b", function() require("dap").toggle_breakpoint() end, desc = "Debug: Toggle breakpoint" },
    },
	},
	{
		"rcarriga/nvim-dap-ui",
		dependencies = { "mfussenegger/nvim-dap", "nvim-neotest/nvim-nio" },
		config = function()
			local dap = require("dap")
			local dapui = require("dapui")
			dapui.setup()
			dap.listeners.after.event_initialized["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
		end,
	},
	{
		"mfussenegger/nvim-dap-python",
		ft = "python",
		dependencies = { "mfussenegger/nvim-dap", "rcarriga/nvim-dap-ui" },
		config = function()
			local path = "~/.local/share/nvim/mason/packages/debugpy/venv/bin/python"
			require("dap-python").setup(path)
		end,
	},
}

@danischn
Copy link

A temporary solution would be to run this in the terminal:

defaults write com.apple.CrashReporter DialogType none

To enable it again:

defaults write com.apple.CrashReporter DialogType prompt

You must restart for the changes to take effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants