pycharm remote debug python in docker

来源:互联网 发布:解题王软件下载 编辑:程序博客网 时间:2024/06/05 01:12

pycharm remote debug python in docker

下载pycharm 2017开发工具个人版或破解版,其中有remote debug的配置

配置中有docker配置,采用本机docker即可
project配置interpreter,可以添加add remote interpreter
选定docker即可,引用已解决的docker配置

打开项目,添加python remote debug

需要注意的是ip要配置:0.0.0.0

0.0.0.0是用于本机监听所有ip的,理论上用192.168.1.14也应该是可以的,但不能用推荐的localhost进行远程调试
port可以配置固定比如:21000
在代码中头部或main部分引入如下语句

import sys
sys.path.append(‘../pycharm-debug.egg’)
import pydevd
pydevd.settrace(‘192.168.1.14’, port=21000, stdoutToServer=True, stderrToServer=True)

192.168.1.14为实体机IP

21000为pycharm设定的调试端口
pycharm-debug.egg
文件是在pycharm安装包下面remote debug目录下找到的,放到项目路径或其他路径下,主要用于加载实际的egg包,便于调试

启动debug模式,控制台会输出如下信息,即表示成功连接了

Starting debug server at port 21000
Use the following code to connect to the debugger:
import pydevd
pydevd.settrace(‘0.0.0.0’, port=21000, stdoutToServer=True, stderrToServer=True)
Waiting for process connection…
Connected to pydev debugger (build 172.3757.67)
Warning: wrong debugger version. Use pycharm-debugger.egg from PyCharm installation folder.


关键的事情是IP不对应可能导致不能调试docker下启动的应用

原创粉丝点击