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

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up