Pycharm Debugger not working in Python Console for Docker-Compose interpreter
Working on an application, my test suite debugger takes a solid six minutes to boot up and run the code I care about. Annoying, but a separate problem from this post.
The class I wanted to test is simple enough, so I tried launching the Python Console. The console launches fine, the remote docker interpreter does what is expected. Code runs, all is well.
However, when I try to run the debugger in the console, I get the following output.
python /opt/.pycharm_helpers/pydev/pydevconsole.py --mode=client --host=host.docker.internal --port=51801
Creating service_app_run ...
Creating service_app_run ... done
import sys; print('Python %s on %s' % (sys.version, sys.platform))
import django; print('Django %s' % django.get_version())
sys.path.extend(['/opt/project/', '/opt/.pycharm_helpers/pycharm', '/opt/.pycharm_helpers/pydev'])
if 'setup' in dir(django): django.setup()
import django_manage_shell; django_manage_shell.run('/opt/project/')
Python 3.8.2 (default, Feb 26 2020, 02:56:10)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.34.0 -- An enhanced Interactive Python. Type '?' for help.
PyDev console: using IPython 7.34.0
Python 3.8.2 (default, Feb 26 2020, 02:56:10)
[GCC 7.4.0] on linux
Django 3.2.12
Debugger connected.
Could not connect to 127.0.0.1: 51804
Traceback (most recent call last):
File "/opt/.pycharm_helpers/pydev/_pydevd_bundle/pydevd_comm.py", line 463, in start_client
s.connect((host, port))
ConnectionRefusedError: [Errno 111] Connection refused
Traceback (most recent call last):
File "/opt/.pycharm_helpers/pydev/_pydev_bundle/pydev_console_utils.py", line 390, in do_connect_to_debugger
self.debugger.connect(host, debuggerPort)
File "/opt/.pycharm_helpers/pydev/pydevd.py", line 660, in connect
s = start_client(host, port)
File "/opt/.pycharm_helpers/pydev/_pydevd_bundle/pydevd_comm.py", line 463, in start_client
s.connect((host, port))
ConnectionRefusedError: [Errno 111] Connection refused
Failed to connect to target debugger.
The one thing I note is that the port the debugger attempts to connect to is a mismatch from the `--port` argument, but I'm not sure if that's germane.
Relevant information:
- macOS 12.6.5 (MacBook Pro, 2019, Intel Core i7)
- PyCharm 2023.1
- Remote Docker interpreter
Possibly relevant information:
- This worked in a previous version of PyCharm; I updated to 2023.1 in order to see if it would help the test suite launch faster. Spoiler: it did not.
- Something changed in a recent version of Docker? PyCharm? that moved `/var/run/docker.sock` to `$HOME/.docker/run/docker.sock`, so I have to run `sudo ln -s $HOME/.docker/run/docker.sock /var/run/docker.sock` to make the PyCharm remote interpreter work
Please sign in to leave a comment.
Unfortunately, this looks like a known issue: https://youtrack.jetbrains.com/issue/PY-53973/ConnectionRefusedError-Errno-111-Connection-refused
Please vote for the thread to receive updates regarding the fix status and workarounds.
I also have the same issue.
Pycharm 2023.2 (MacOS Ventura 13.5.1)
(Debugging scripts works, console without debugger works but when attaching a debugger to the console, I get the error posted above)