Pycharm实现python远程调试

Author Avatar
LittleYou Don't Know 10月 19, 2016
  • 在远程客户端[linux]安装pycharm-debug.egg 首先,下载安装easy_install的安装脚本
    1
    2
    #wget https://bootstrap.pypa.io/ez_setup.py
    #python ez_setup.py

pycharm-debug.egg文件在Pycharm安装目录下的debug-eggs文件夹中

1
#easy_install pycharm-debug.egg

类似地,在服务端[Windows]中安装pycharm-debug.egg

1
2
>python ez_setup.py
>easy_install.exe pycharm.egg

  • 在Pycharm中配置Remote Debug Edit Configuration->+>Python Remote remote_debug

Local host name 填写Windows服务端IP
Port 填写任意未被占用端口

  • 测试:在客户端python脚本中添加如下
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    #vim remote.py
    #!/usr/bin/env python
    import pydevd
    def debugtest():
    pydevd.settrace('192.168.22.148', port=9901, stdoutToServer=True, stderrToServer=True)
    a = 10
    b = 20
    c = a + b
    print c
    if __name__ == "__main__":
    debugtest()

最后,打开自定义的Remote debug,并在客户端执行该脚本文件 可以看到如下
PS:客户端无法Ping通Windows时,在防火墙->高级->入站规则 中启用ICMP