red*_*888 7 python intellij-idea intellij-plugin docker
我有一个python应用程序,但根据文档,调试端口仅支持java.
如何在intellij中设置断点并调试我的python容器?有没有办法让python容器连接到intellij python调试器?
编辑:我正在运行Windows 10,Windows的docker,容器是linux.也许我需要为intellij Python调试器手动设置某种远程调试?另外,不妨问一下,我是否必须拥有专业版进行远程调试,或者是否有使用社区的解决方法?
您可以使用Python远程调试来实现.打开配置窗口,然后单击+ - > Python Remote Debug
然后你设置一个端口或保持空白,以便Pycharm找到一个可用的端口.
然后单击Debug图标以启动调试服务器,该服务器将显示以下类型的消息
Starting debug server at port 57588
Use the following code to connect to the debugger:
import pydevd
pydevd.settrace('localhost', port=57588, stdoutToServer=True, stderrToServer=True)
Waiting for process connection...
Run Code Online (Sandbox Code Playgroud)
现在你需要在docker中设置pydev调试.你需要pycharm-debug-py3k.egg这个.对我来说,我复制到我当前的Dockerfile文件夹,如下所示
cp "/Users/tarun.lalwani/Library/Application Support/IntelliJIdea2017.2/python/pycharm-debug-py3k.egg" .
Run Code Online (Sandbox Code Playgroud)
您将根据安装的IntelliJ版本更改位置.之后,我们需要编辑Dockerfile
FROM python:3.6
WORKDIR /app
ENV PYTHONPATH=/app:/app/debug
COPY pycharm-debug-py3k.egg /app/debug
COPY debug_test.py /app/
CMD python debug_test.py
Run Code Online (Sandbox Code Playgroud)
在debug_test.py构建时将有低于顶线
import pydevd
pydevd.settrace('docker.for.mac.localhost', port=55507, stdoutToServer=True, stderrToServer=True)
Run Code Online (Sandbox Code Playgroud)
注意:我使用的
docker.for.mac.localhost是因为我使用docker for mac,但如果使用Docker for windows则使用docker.for.win.localhost.对于工具箱或Linux,您将添加机器的IP
由于它是docker,我们可能希望保持端口固定而不是像我那样动态.现在我们构建docker文件并运行它.
这将在pycharm中打开一个弹出窗口,单击自动检测以检测源映射
然后,您将在文件的主行中断开您的代码
| 归档时间: |
|
| 查看次数: |
2698 次 |
| 最近记录: |