PythonTip >> 博文 >> python PyCharm

利用Pycharm对python代码进行远程调试

zihua 2014-03-05 15:03:41 点击: 1617 | 收藏


一.介绍

使用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/

在Client/Server端安装easy_install.

本例中server端提供pycharm调试IDE,开放debug端口,系统是win7。client端是实际程序执行的环境,本例中是在linux下的一段简单的小程序

在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

window服务器端安装

下载脚本

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

在服务器端配置Pycharm

配置远程调试

打开PvCharm,配置远程调试:

(a).  打开 Edit confiurations

(b).  添加 Python Remote Debug

(c).  配置本地的 Local host name、Port . Local host name 是本机的IP。Port在保证不冲突的情况下可以任意指定

执行该debug的配置时,状态栏会出现 “waiting for connection”, 表示正在等待客户端主动连接

修改客户端的python脚本

将红色内容添加到需要调试的脚本中

import pydevd

def debugtest():
        pydevd.settrace("192.168.40.146", port=8877)
        a=10;
        b=10

debugtest()

在客户端执行脚本

server 端捕获到程序执行路径,且显示变量

 

原文链接:http://www.tuicool.com/articles/RJjiE3

作者:zihua | 分类: python PyCharm | 标签: python PyCharm | 阅读: 1617 | 发布于: 2014-03-05 15时 |