Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ModuleNotFoundError: No module named '_ctypes' Mac M1

Tags:

python

macos

While installing some libraries you may find the issue ModuleNotFoundError: No module named '_ctypes'

like image 704
user3447228 Avatar asked Dec 02 '25 16:12

user3447228


2 Answers

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.

like image 135
rvd Avatar answered Dec 04 '25 05:12

rvd


Make sure you are running python 3.8.10 +

like image 25
user3447228 Avatar answered Dec 04 '25 07:12

user3447228



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!