15

I am using JetBrains Pycharm IDE in ubuntu 18.04

when I am hitting run, it is working fine but debugging is failing every time with the following error.

error screenshot

and this is prompt from debug button

Connection to Python debugger failed Socket closed

I tried these, but couldn't make it work :

  1. uninstalling pycharm

  2. editing interpreter location

  3. removing virtual environment

  4. tried changing debugger port

this is my configuration file

configuration details

please help me with this issue

Satyaaditya
  • 436
  • 1
  • 3
  • 9

8 Answers8

15

After a hell lot of searching and experimenting, found the solution for my issue.

My repo consists of a module named code in it. Similarly, python has a same-named module for debugging, which creating a clash and debugger unable to reach that code.

I renamed it, and it's working like charm now. Had similar issue with 'test' as a module name

Satyaaditya
  • 436
  • 1
  • 3
  • 9
  • 2
    I can confirm this. On my end I was working through the code examples from Brian Okken's 'Python Testing with Pytest'. The root directory for the provided code examples was named 'code'. I changed that to 'code-book', and debugging via Pytest in PyCharm now works as it should. – xax Sep 02 '19 at 02:46
  • In other cases, try marking the root of your directory as "sources root". PyCharm Python interpreter will rely on it to load respective module to debug. – Dio Phung Sep 14 '22 at 23:04
2

I had/have Python Community Edition (2019.1.1, now 2019.3.3) installed on Windows laptop. I named a new file "String". It took some time before I realized it was the name which caused the debugger to fail. The message I received was "connection to python debugger failed interrupted function call accept failed" . The failure was caused solely by the improper naming of the file. I tested again on version 2019.3.3, the name "string" causes the same failure of the debugger to connect and connection is fine when I change the file name to something else.

2

Got the same issue on Pycharm Professional 2021.1 on Windows, because of a file I named types.py,

renaming it got the debugger to run.

Dor
  • 21
  • 1
0

I think, the issue of problem is due to "Project" relation. I have confused about debugging trouble. At a moment, I could'nt using the Debug tool in PyCharm, I used to it well before. There are some different about the Project characterization between "PyCharmProjects" and "PythonProject". If you used "PyCharmProjects" at first, it is no trouble. Later you may create new project as "PythonProject", you wouldn't using debug tool in PyCharm. This is in my case, I hope someone get help from this hint.

0

I had to rename a file named "site.py" to something else to get my debugger to work again.

0

I had to rename a file named "inspect.py" to something else to get my debugger to work again.

0

I solved it by disabling "PyQt compatible" checkbox in the Settings > Build, Execution, Deployment > Python Debugger as found here.

0

For me, it wasn't the accepted answer that did the job but it was the firewall that blocked the debugger.

What solved it for me was a combination of [1], [2]:

  1. edit /etc/default/ufw to change DEFAULT_FORWARD_POLICY's value to "ACCEPT"
  2. ufw allow in on docker0
  3. sudo ufw reload
jonka
  • 1