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/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/christoff/.pyenv/versions/3.7.12/lib/python3.7/runpy.py", 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/__main__.py", line 97, in <module>
    main()
  File "/home/christoff/.vscode/extensions/ms-python.python-2021.12.1559732655/pythonFiles/lib/python/debugpy/launcher/__main__.py", 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/debuggee.py", line 8, in <module>
    import ctypes
  File "/home/christoff/.pyenv/versions/3.7.12/lib/python3.7/ctypes/__init__.py", line 7, in <module>
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'

python versions output:

  system
* 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:

https://stackoverflow.com/questions/27022373/python3-importerror-no-module-named-ctypes-when-using-value-from-module-mul

sudo pacman -S libffi
pyenv uninstall 3.7.12
pyenv install 3.7.12