Skip to content

More OSX issues on 0.8 with debugpy #16

Description

@MattReimer

This is tangential to #12 and #13 but not entirely the same.

Details:

  • QGIS LTR 3.34.5-Prizren
  • OSX: Sonoma 14.4.1
  • VSCode: Version: 1.88.0
  • VSCode Python Extension: v2024.4.0
  • VSCode Python Debugger Extension: v2024.4.0

The problems:

  • When I click the button in this plugin it pops open a completely new instance of QGIS... which is very weird. I never found out why that was happening.
  • I did see an error relating to cannot import name 'absolute_path' from 'pydevd_file_utils' ( but I found that it was a conflict with ptvsd and that removing ptvsd solved that issue.
  • It seems like debugpy needs to be configured with the python executable path (which is sirprisingly difficult to find because sys.executable gives you the /Applications/QGIS-LTR.app/Contents/MacOS/QGIS folder which is not helpful)

My workarounds:

  1. Make sure debugpy is installed using /Applications/QGIS-LTR.app/Contents/MacOS/bin/pip3 install debugpy
  2. uninstall ptvsd completely using /Applications/QGIS-LTR.app/Contents/MacOS/bin/pip3 uninstall ptvsd

Here's what I baked into my plugin to get it working again. I'm triggering the debugger on an environment variable called RS_DEBUG being set to True.

    def _enable_debug(self):
        debug_port = 5678
        debug_host = "localhost"
        DEBUG_ON = os.environ.get("RS_DEBUG", "False").lower() == "true"
        if not DEBUG_ON:
            return

        if self.debugpy is None:
            try:
                import debugpy
                self.debugpy = debugpy
            except:
                pass

        if self.debugpy is None:
            return
        else:
            try:
                python_path = os.path.join(Path(os.__file__).parents[2], 'bin', Path(os.__file__).parent.name)
                # NOTICE THAT I NEED TO CONFIGURE IT HERE!!!!!
                debugpy.configure(python=python_path) 
            except Exception as e:
                raise e

        msgPort = f'"request": "attach", "Port": {debug_port}, "host": "{debug_host}"'
        if self.debugpy.is_client_connected():
            return
        else:
            t_, new_port = self.debugpy.listen((debug_host, debug_port))

then using the following in my launch.json file inside vscode I was able to get a client connecting and breakpoints firing again.

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "QGIS Debug",
      "type": "debugpy",
      "request": "attach",
      "connect": {
        "host": "localhost",
        "port": 5678
      },
      "pathMappings": [
        {
          "localRoot": "${workspaceFolder}",
          "remoteRoot": "${workspaceFolder}",
        }
      ],
      "justMyCode": true
    },
  ]
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions