Can't run Debugger - 'Connection to Python debugger failed; Socket closed'


I've been trying to get the debugger to work on a remote work station but I keep having this error pop up when trying to debug a code/script. Interestingly enough, when I run my scripts normally, I my codes execute without issue, but I really need the debugging tool when creating other scripts. I have tried creating a brand new projects but when I run the debugger again, I have this error pop up.

/mnt/home/jpsc230/anaconda3/envs/rcrest19/bin/python /mnt/home/jpsc230/pycharm-community-2020.1/plugins/python-ce/helpers/pydev/ --multiproc --qt-support=auto --client --port 45959 --file /hd2/work/jon/py/pythonProject/rcrest19/
Traceback (most recent call last):
File "/mnt/home/jpsc230/pycharm-community-2020.1/plugins/python-ce/helpers/pydev/_pydevd_bundle/", line 55, in <module>
from _pydevd_bundle.pydevd_cython_wrapper import trace_dispatch as _trace_dispatch, global_cache_skips, global_cache_frame_skips, fix_top_level_trace_and_get_trace_func
File "/mnt/home/jpsc230/pycharm-community-2020.1/plugins/python-ce/helpers/pydev/_pydevd_bundle/", line 48, in <module>
raise exc

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/mnt/home/jpsc230/pycharm-community-2020.1/plugins/python-ce/helpers/pydev/", line 49, in <module>
from _pydevd_bundle.pydevd_trace_dispatch import (
File "/mnt/home/jpsc230/pycharm-community-2020.1/plugins/python-ce/helpers/pydev/_pydevd_bundle/", line 63, in <module>
File "/mnt/home/jpsc230/pycharm-community-2020.1/plugins/python-ce/helpers/pydev/_pydevd_bundle/", line 19, in delete_old_compiled_extensions
cython_extensions_dir = os.path.dirname(os.path.dirname(_pydevd_bundle_ext.__file__))
File "/mnt/home/jpsc230/anaconda3/envs/rcrest19/lib/python3.8/", line 152, in dirname
p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType

Process finished with exit code 1



I have seen other people that had issues with "Socket closed" errors, but usually those instances were resolved with renaming/deleting a script/code they had named '' or something to that effect. I don't believe that is the issue here. Any help or direction is greatly appreciated.




The issue seems to be the same as, which is not fixed yet.

Does it help if you add PYDEVD_USE_CYTHON=NO environment variable to your run configuration (Run | Edit Configurations...)?

If not, try the workaround from this comment


Adding ;PYDEVD_USE_CYTHON=NO to the configuration seems to have been a sufficient work around. Is there way to set this as a sort of 'default' for a project? I'm assuming this is an error that will be addressed in future releases of Pycharm? Thanks for the help by the way! Sorry to post a redundant instance.


Sure, you can add it to the run configuration template. Each new run config will have it by default, but you still need to add it to the existing ones.

Yes, we'll fix it for sure, but I can't provide you with ETA yet.



I'm trying to debug within pytest. Adding `PYDEVD_USE_CYTHON=NO` to the configuration stops the socket crashing, but the debugger is broken. Stepping into code takes me into pytest code rather than my application code. Will take a lot of time for me to rewrite fixtures to debug outside of pytest.


Peter Goodall

Could you please submit an issue to with the code sample and steps to reproduce?


Thanks, Sergey Karpov! The photo helped me to fix the issue.


i moved my files to primary location of pycharm and debugging works!!

before that my files was on personal location that i made .


I face this issue always in PyCharm as  ‘Connection to Python debugger failed : Socket closed’
I tried changing the environment variable to PYDEVD_USE_CYTHON=NO
Still faced the same issue
And tried changing the environment variable to PYTHONUNBUFFERED=1
Still faced the same issue
I face the below error in console after debugging the code .

"C:\Program Files\Python311\python.exe" "C:/Users/Sekar/PyCharm Community Edition 2023.2.1/plugins/python-ce/helpers/pydev/" --multiprocess --save-signatures --client --port 50986 --file C:\Users\Sekar\PycharmProjects\Pythonsept\ 
Traceback (most recent call last):
  File "C:\Users\Sekar\PyCharm Community Edition 2023.2.1\plugins\python-ce\helpers\pydev\", line 40, in <module>
    import pydevd_tracing
  File "C:\Users\Sekar\PyCharm Community Edition 2023.2.1\plugins\python-ce\helpers\pydev\", line 1, in <module>
    import ctypes
  File "C:\Program Files\Python311\Lib\ctypes\", line 163, in <module>
    _check_size(py_object, "P")
  File "C:\Program Files\Python311\Lib\ctypes\", line 153, in _check_size
    raise SystemError("sizeof(%s) wrong: %d instead of %d" % \
SystemError: sizeof(<class 'ctypes.py_object'>) wrong: 8 instead of 0

I tried unticking PyQT compatibility also in Python Debugger and still face the issue for debugging.

Please anyone help me with further recoveries please


Siddhusir23 It seems the issue happens when importing ctypes. Please try running Python from “C:\Program Files\Python311” and execute “import ctypes”. Does it work?


Yeah its not working and throws the same system error.
Program is running from C:ProgramFiles\Python311\python.exe
But still face this ctype error.

any environment variable to change please let me know.
Can you please help me with this ctypes part and how to resolve on this

Well, it looks like a python issue. Please try reinstalling it from

Working for me: delete the Path in Working directory of your run/debug configuration


Still facing the same issue on Idea CE : 'Connection to Python debugger failed; Socket closed'


For me it worked after reinstalling / restarting Pycharm with New Project. 
Try running Py in Virtual Environment.
Thanks !

A socket closed error usually signifies that the socket is already in use in the system. Rebooting the system might be helpful in most cases.
Also, removing the run configuration for your file (Run | Edit Configurations) and regenerating it again by running a file with the default run config might be helpful.

Please sign in to leave a comment.