Skip to content

Instantly share code, notes, and snippets.

@AsgerPetersen
Last active June 23, 2020 14:44
Show Gist options
  • Save AsgerPetersen/bd75632848dc9277251ac421ded90444 to your computer and use it in GitHub Desktop.
Save AsgerPetersen/bd75632848dc9277251ac421ded90444 to your computer and use it in GitHub Desktop.
PyCharm remote debug of QGIS on OSX

Based heavily on this old guide by TimLinux http://linfiniti.com/2012/09/remote-debugging-qgis-plugins-using-pycharm/

  • In PyCharm click menu "Run -> Edit Configurations" (Or click Edit Configurations in the dropdown in the toolbar)
  • Click the plus to add a new "Python Remote Debug" config
  • Name the config. Use port 53100 (Could probably be any high port)
  • Add to the python code:
import sys
sys.path.append('/Applications/PyCharm.app/Contents/debug-eggs/pycharm-debug.egg')
import pydevd
pydevd.settrace('localhost', port=53100, stdoutToServer=True, stderrToServer=True)
  • In PyCharm run the newly made Python Remote Debug configuration. The PyCharm console will print something like
Starting debug server at port 53100
Use the following code to connect to the debugger:
import pydevd
pydevd.settrace('localhost', port=53100, stdoutToServer=True, stderrToServer=True)
Waiting for process connection...
  • Now activate/reload your plugin in QGIS.

If everything goes well your PyCharm console will now print

Connected to pydev debugger (build 143.1919.2)

Now PyCharm debugger will break at the line

pydevd.settrace('localhost', port=53100, stdoutToServer=True, stderrToServer=True)

As if it where a regular break point. Continuing from here just use PyCharm break points.

@blazek
Copy link

blazek commented May 25, 2017

Note that Remote Debugging is supported in the Professional edition only.
https://www.jetbrains.com/help/pycharm/remote-debugging.html

@NicolaiLolansen
Copy link

This also works in Windows 10 PyCharm Professional if you change the path pointing to the pycharm-debug.egg file.

something like this: C:\Program Files\JetBrains\PyCharm 2017.3.3\debug-eggs\pycharm-debug.egg

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