One of the quirks in remote debugging an application with PyCharm is that you need to be able to import the proper pydevd package.  This tends to change location with every PyCharm installation and update.  Rather than hardcode these paths and check against the installed version of PyCharm to locate them, I’ve found it convenient to simply use a running instance of PyCharm to locate the location of the pydevd that I need to import into the client app.

Once you have the path, you can append it to you sys.path or import it directly with a module like “imp”.

Eitherway, here is the snippet that locates pydevd for the running instance of PyCharm…

import os
import sys
import win32com.client

def get_pydevd_path():
	Gets the pydevd path based on locating the executable path of a running PyCharm process.


	**Keyword Arguments:**

		:``pydevd_path``: `<str>` E.G. "C:/Program Files (x86)/JetBrains/PyCharm 4.0.1/pycharm-debug.egg"

	pydev_path = None

	WMI = win32com.client.GetObject( 'winmgmts:' )
	processes = WMI.InstancesOf('Win32_Process')

	for process in processes:
		if 'pycharm' in process.Properties_('Name').Value:
			path = process.Properties_('ExecutablePath').Value
			p = os.path.abspath(os.path.join( os.path.dirname(str(path)), '../debug-eggs/pycharm-debug.egg'))
			if os.path.exists( p ):
				pydev_path = p

	return pydev_path