Installing libffi-dev and re-installing python3.7 fixed the problem for me.
to cleanly build py 3.7 libffi-dev is required or else later stuff will fail
If using RHEL/Fedora:
sudo yum install libffi-devel
or
sudo dnf install libffi-devel
If using Debian/Ubuntu:
sudo apt-get install libffi-dev
Answer from dotbit on Stack OverflowInstalling libffi-dev and re-installing python3.7 fixed the problem for me.
to cleanly build py 3.7 libffi-dev is required or else later stuff will fail
If using RHEL/Fedora:
sudo yum install libffi-devel
or
sudo dnf install libffi-devel
If using Debian/Ubuntu:
sudo apt-get install libffi-dev
If you use pyenv and get error "No module named '_ctypes'" (like i am) on Debian/Raspbian/Ubuntu you need to run this commands:
sudo apt-get install libffi-dev
pyenv uninstall 3.7.6
pyenv install 3.7.6
Put your version of python instead of 3.7.6
az functionapp - fails with ModuleNotFoundError: No module named 'ctypes' in SAW
Pipenv lock : ModuleNotFoundError: No module named '_ctypes'
ModuleNotFoundError: No module named '_ctypes_test' (Debugger on Windows)
Installing ctypes
Why does No module named _ctypes happen?
How do I check whether _ctypes is available?
Can reinstalling a package fix _ctypes?
Required
Install foreign function interface headers
sudo apt install libffi-dev
Reinstall Python
Substitute desired python version
Ubuntu
sudo add-apt-repository ppa:deadsnakes/ppa -y && sudo apt install --reinstall python3.9-distutils
MacOS
Use brew install python3.9 or port install python3.9 (I recommend port)
Windows
Use Microsoft Store
Specify project python version
Poetry
poetry env use 3.9
Virtual envs
virtualenv -p python3.9 myproject
etc...
As other answers say, you need to install libffi-dev. If you're using pyenv/virtualenv, also reinstall the base python version:
Install libffi
sudo apt-get install libffi-dev
Load the new libffi.so, as suggested here
sudo ldconfig
Reinstall the python version available to pyenv
pyenv install 3.9.12
Finally, create the fresh virtualenv
pyenv virtualenv 3.9.12 new_environment
How to install ctypes on Windows? I searched on the web a bit but couldn't find anything.