如何在intellij中debuggingpython容器?
docker插件有一个连接到容器的debugging端口
我有一个Python应用程序,但根据文档debugging端口只支持Java。
我怎样才能设置断点和debugging我的Python容器intellij? 有什么办法可以让python容器连接到intellij pythondebugging器?
编辑:我运行的是Windows 10,Docker for Windows,容器是linux。 也许我需要为intellij Pythondebugging器手动设置某种远程debugging? 另外,不妨问一下,我必须有专业的远程debugging版本,或者有一个使用社区的解决方法吗?
你可以使用Python Remote Debugging来完成。 打开configuration窗口并点击+ – > Python Remote Debug
然后,您可以设置一个端口或将其保留为空以供Pycharm查找可用的端口。
然后点击debugging图标启动debugging服务器,将显示下面的消息types
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...
现在你需要在docker中设置pydevdebugging。 你将需要这个pycharm-debug-py3k.egg
。 对我来说,我复制到我目前的Dockerfile文件夹,如下所示
cp "/Users/tarun.lalwani/Library/Application Support/IntelliJIdea2017.2/python/pycharm-debug-py3k.egg" .
您的位置将根据所安装的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
debug_test.py
时的debug_test.py
将在顶部有下面的行
import pydevd pydevd.settrace('docker.for.mac.localhost', port=55507, stdoutToServer=True, stderrToServer=True)
注意:我使用
docker.for.mac.localhost
因为我使用docker.for.mac.localhost
for mac,但是如果使用Docker for windows,则使用docker.for.win.localhost
。 对于工具箱或Linux,您将添加您的机器的IP
既然是docker工人,我们可能想保持固定的港口,而不是像我一样dynamic。 现在我们构builddocker文件并运行它。
这将在pycharm中打开一个popup窗口,点击autodetect检测源映射
然后你将你的代码放在文件的主线上