DEV Community

Doctorx
Doctorx

Posted on

1 1

Remote debug with pydevd-pycharm for PyCharm

Motivation

It is the second attempt to set up this configuration, and I forgot what I did in the previous approach. My notes what How I set up configuration.

Project

Project-based on Django. The project uses a Docker and a docker-compose. Pycharm uses a Python interpreter from docker-compose. We separate the project into two services:

  • Celery
  • API

Debugging

For API I use PyCharm Django debugger. Work fine and does not have any problems. But when I need to debug the Celery task. We have an issue with the classical debugger.
Pydevd-pycharm server good resolved the problem with it.

Setup

  • Dockerfile. pip install pydevd-pycharm-
  • Put to problem part of code:
import pydevd_pycharm
pydevd_pycharm.settrace('host.docker.internal', port=7777, stdoutToServer=True, stderrToServer=True)
Enter fullscreen mode Exit fullscreen mode

Attention: host.docker.internal hostname of host machine in a container.

  • Mapping folders between a host project and a container copy project.

  • Setup Python Debug Server in Pycharm. Where we find instruction how to setup pydevd-pycharm. Host: localhost Port: 7777

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay