While installing some libraries you may find the issue ModuleNotFoundError: No module named '_ctypes'
While installing some libraries you may find the issue ModuleNotFoundError: No module named '_ctypes'
Short version:
Try installing python 3.7.13 with pyenv:
pyenv install 3.7.13, and if that does not work, try python 3.7.12 (pyenv install 3.7.12).
The pyenv release 2.2.3 addresses the compilation problems for 3.6.15/3.7.12 on M1 macs, specifically for ctypes.
Long version:
The underlying cause for the _ctypes error seems to be that libffi cannot be found during the compilation, and is therefore (silently) skipped during the Python installation.
There is a comprehensive overview for installing different versions using pyenv at this page, some specific versions require homebrew patches. Here is an overview of those patches. However, I would try installing them without the patches first, as the pyenv team has fixed various compilation problems since that post was written.
The general syntax for installing with a patch is:
pyenv install --patch X.X.X <<(curl -sSL link_to_patch) where X.X.X is the version you want to install.
Another solution is to use an x86 version of homebrew.
Officially, Python 3.7 and lower are not supported on Apple Silicon.