一.介绍
使用Python的过程中经常需要对代码进行跟踪调试,PDB虽然也可以,但是Pycharm显得更加的人性化,下文简单的描述使用pycharm进行远程debug的简单步骤
详细描述请参见: http://www.jetbrains.com/pycharm/webhelp/remote-debugging.html
关于PDB的使用方法可参见:http://www.ibm.com/developerworks/cn/linux/l-cn-pythondebugger/
本例中server端提供pycharm调试IDE,开放debug端口,系统是win7。client端是实际程序执行的环境,本例中是在linux下的一段简单的小程序
下载自动安装easy_install的脚本:
$wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
执行脚本
$python ez_setup.py
安装pydevd, 在PyCharm的安装目录下能找到pycharm-debug.egg
$easy_install pycharm-debug.egg
下载脚本
https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
运行脚本
python ez_setup.py
安装pydevd, 在PyCharm的安装目录下能找到pycharm-debug.egg
easy_install.exe pycharm-debug.egg
打开PvCharm,配置远程调试:
(a). 打开 Edit confiurations
(b). 添加 Python Remote Debug
(c). 配置本地的 Local host name、Port . Local host name 是本机的IP。Port在保证不冲突的情况下可以任意指定
执行该debug的配置时,状态栏会出现 “waiting for connection”, 表示正在等待客户端主动连接
将红色内容添加到需要调试的脚本中
import pydevd
def debugtest():
pydevd.settrace("192.168.40.146", port=8877)
a=10;
b=10
debugtest()
server 端捕获到程序执行路径,且显示变量