Remote debugging with Pycharm
一、在远程计算机上,需要:
-
pydevd模块(在本地开发环境的PyCharm安装路径中找到pycharm-debug.egg文件(若远程计算机运行的是Python3,则需要pycharm-debug-py3k.egg),rename as pydevd for brevity.)
-
default.py文件(文件名不重要),内容如下:
#!/usr/bin/env python # coding=utf-8 """ Sets the packages path and optionally starts the Python remote debugging client. The Python remote debugging client depends on the settings of the variables defined in debug_conf.py. Set these variables in debug_conf.py to enable/disable debugging using either the JetBrains PyCharm or Eclipse PyDev remote debugging packages which must be copied to packages/pydebug. """ import os import sys module_dir = os.path.dirname(os.path.realpath(__file__)) # packages = os.path.join(module_dir, u'packages') # sys.path.insert(0, module_dir) sys.path.append(os.path.join(module_dir, 'pydebug')) remote_debugging = { 'client_package_location': os.path.join(module_dir, 'pydebug'), 'is_enabled': False, 'host': None, 'stderr_to_server': False, 'stdout_to_server': False, 'port': 15679, 'suspend': True, 'trace_only_current_thread': False, 'overwrite_prev_trace': False, 'patch_multiprocessing': False} def configure_remote_debugging(): configuration_file = os.path.join(module_dir, 'debug_conf.py') if not os.path.exists(configuration_file): return execfile(configuration_file, remote_debugging) if remote_debugging['is_enabled'] and os.path.exists(remote_debugging['client_package_location']): import pydevd try: pydevd.settrace( remote_debugging['host'], remote_debugging['stderr_to_server'], remote_debugging['stdout_to_server'], remote_debugging['port'], remote_debugging['suspend'], remote_debugging['trace_only_current_thread'], remote_debugging['overwrite_prev_trace'], remote_debugging['patch_multiprocessing']) except SystemExit as e: pass # don't stop just because we couldn't connect to the debugger configure_remote_debugging()
-
debug_conf.py文件(所有可能需要修改的东西放在了这个文件里面~),内容如下:
#!/usr/bin/env python host = 'localhost' port = 15679 suspend = False is_enabled = True