Error while using VSCode debugger extension with Python files!

Hey everyone! I’m having problems using debugger extension on VSCode for debugging python files on Ubuntu 20.04. I also use poetry and pyenv. I got this traceback on vscode terminal:

cd /home/nath/py-try ; /usr/bin/env /home/nath/.cache/pypoetry/virtualenvs/py-try-Phd6N67Q-py3.9/bin/python /home/nath/.vscode/extensions/ms-python.python-2022.0.1814523869/pythonFiles/lib/python/debugpy/launcher 34685 -- /home/nath/py-try/p1.py 
Traceback (most recent call last):
  File "/home/nath/.pyenv/versions/3.9.2/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/nath/.pyenv/versions/3.9.2/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/nath/.vscode/extensions/ms-python.python-2022.0.1814523869/pythonFiles/lib/python/debugpy/launcher/__main__.py", line 97, in <module>
    main()
  File "/home/nath/.vscode/extensions/ms-python.python-2022.0.1814523869/pythonFiles/lib/python/debugpy/launcher/__main__.py", line 24, in main
    from debugpy.launcher import debuggee
  File "/home/nath/.vscode/extensions/ms-python.python-2022.0.1814523869/pythonFiles/lib/python/debugpy/launcher/../../debugpy/launcher/debuggee.py", line 8, in <module>
    import ctypes
  File "/home/nath/.pyenv/versions/3.9.2/lib/python3.9/ctypes/__init__.py", line 8, in <module>
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'

and this prompt: Timed out waiting for launcher to connect.

launch.json file configuration is as follow:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        }
    ]
}

I also looked up for the documentation Debugging configurations for Python apps in Visual Studio Code and tried changing the console config to “internalConsole” and “externalTerminal”, I also tried changing the Python debug option to “Current File” to “Debug Console”, but this doesn’t work yet.

I’m wondering what the problem is, if someone could help me.

do you have this module?

1 Like

Yeah, this was the solution. I solved it by uninstalling all my pyenv virtual environments and installing

sudo apt-get install libffi-dev

Then reinstalling the envs.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.