No module named _ctypes error Python 3.7.12

I am trying to setup my Manjaro GNOME for Python development. The project is a Flask project.

The project requires Python 3.7.12. I have installed the correct version using pyenv.

When building the project (all the commands are specified in a makefile), the correct venv is created using the correct python version. However, whenever I try to install and run the project through VSCode, I simply get the error stating ModuleNotFoundError: No module named '_ctypes'

I have tried reinstalling pyenv using various methods on their GitHub page. When running pyenv version in terminal, I do get the correct version of Python.

If anyone has any idea on how I could solve this issue, I would greatly appreciate it.

The full error when trying to run the project:

Traceback (most recent call last):
  File "/home/christoff/.pyenv/versions/3.7.12/lib/python3.7/", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/christoff/.pyenv/versions/3.7.12/lib/python3.7/", line 85, in _run_code
    exec(code, run_globals)
  File "/home/christoff/.vscode/extensions/ms-python.python-2021.12.1559732655/pythonFiles/lib/python/debugpy/launcher/", line 97, in <module>
  File "/home/christoff/.vscode/extensions/ms-python.python-2021.12.1559732655/pythonFiles/lib/python/debugpy/launcher/", line 24, in main
    from debugpy.launcher import debuggee
  File "/home/christoff/.vscode/extensions/ms-python.python-2021.12.1559732655/pythonFiles/lib/python/debugpy/launcher/../../debugpy/launcher/", line 8, in <module>
    import ctypes
  File "/home/christoff/.pyenv/versions/3.7.12/lib/python3.7/ctypes/", line 7, in <module>
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'

python versions output:

* 3.7.12 (set by /home/christoff/.pyenv/version)

Thank you!

According to this issue you have to install libffi package and reinstall your particular python version:

sudo pacman -S libffi
pyenv uninstall 3.7.12
pyenv install 3.7.12