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.

Answer from rvd on Stack Overflow
🌐
GitHub
github.com › pypa › pipenv › issues › 4901
mac m1 python3.7 ModuleNotFoundError: No module named '_ctypes' · Issue #4901 · pypa/pipenv
December 26, 2021 - I'm using m1 mac with pyenv. I installed python 3.7.12. Then: python -m pip install pipenv After that: pipenv install --dev And got: File "/Users/admin/.pyenv/versions/3.7.10/lib/python3.7/ctypes/__init__.py", line 7, in <module> from _ctypes import Union, Structure, Array ModuleNotFoundError: No module named '_ctypes' Pipfile.lock (cc931a) out of date, updating to (883ee9)...
Author: pypa
🌐
GitHub
github.com › pypa › pipenv › issues › 5104
Mac M1 python 3.8.2-3.8.12 ModuleNotFoundError: No module named '_ctypes' · Issue #5104 · pypa/pipenv
May 17, 2022 - Hello there. I have the same issue as #4901 Mac Air M1, Monterey 12.4 But for python version 3.8.2 and 3.8.12 (router) gespover@MacBook-Air-Stepan router % pipenv install Traceback (most recent cal...
Author: pypa
People also ask

What is Python ModuleNotFoundError and what causes it?
ModuleNotFoundError (a subclass of ImportError) is raised when Python cannot find the module you tried to import. Common causes: the package isn't installed (pip install missing), wrong virtual environment activated, typo in module name, or Python can't find your local module on the import path. The error message names exactly which module is missing.
🌐
itsourcecode.com
itsourcecode.com › home › modulenotfounderror: no module named _ctypes [fixed]
Modulenotfounderror: no module named _ctypes [Fixed] (2026)
How do I fix 'ModuleNotFoundError: No module named X'?
Run pip install X first. If that succeeds but you still get the error, check which Python you're using (which python OR python --version) vs which pip (which pip OR pip --version), they must match. Common gotcha: pip points to system Python 3.9 but you're running python3.11 in a venv. Inside the venv, use python -m pip install X to be sure pip matches the active Python.
🌐
itsourcecode.com
itsourcecode.com › home › modulenotfounderror: no module named _ctypes [fixed]
Modulenotfounderror: no module named _ctypes [Fixed] (2026)
Is ModuleNotFoundError the same as ImportError?
ModuleNotFoundError is a subclass of ImportError added in Python 3.6. It specifically means 'no such module exists.' Plain ImportError covers a wider set: module exists but a name inside it can't be imported (e.g. 'cannot import name X from Y'). except ImportError catches both; except ModuleNotFoundError catches only the missing-module case.
🌐
itsourcecode.com
itsourcecode.com › home › modulenotfounderror: no module named _ctypes [fixed]
Modulenotfounderror: no module named _ctypes [Fixed] (2026)
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-fix-modulenotfounderror-no-module-named-ctypes
How to Fix ModuleNotFoundError: No Module Named '_ctypes' - GeeksforGeeks
July 23, 2025 - When Python encounters the "ModuleNotFoundError: No module named '_ctypes'" error, it means that the '_ctypes' module is unavailable for a reason causing the interpreter to fail when trying to import it.
🌐
Python Pool
pythonpool.com › home › error › fix no module named _ctypes in python
[Solved] ModuleNotFounderror: No Module named _ctypes in ...
July 13, 2026 - On Fedora-style systems, install the matching libffi development package for that distribution. On macOS, install or repair libffi through the package manager used for your Python, then reinstall the affected Python.
🌐
DEV Community
dev.to › ajkerrigan › homebrew-pyenv-ctypes-oh-my-3d9
Homebrew, pyenv, ctypes... oh my! - DEV Community
January 4, 2022 - >>> import ctypes Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/tmp/python-build.20211231145343.269699/Python-3.10.0/Lib/ctypes/__init__.py", line 8, in <module> from _ctypes import Union, Structure, Array ModuleNotFoundError: No module named '_ctypes'
🌐
Python
bugs.python.org › issue32095
Issue 32095: AIX: ModuleNotFoundError: No module named '_ctypes' - make install fails - Python tracker
This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide · This issue has been migrated to GitHub: https://github.com/python/cpython/issues/76276
Find elsewhere
🌐
Delft Stack
delftstack.com › home › howto › python › modulenotfounderror no module named _ctypes
How to Solve ModuleNotFoundError: No Module Named '_Ctypes' in Python | Delft Stack
February 12, 2024 - Required Packages: Reinstall or upgrade packages related to '_ctypes' that might be broken or outdated using commands like pip uninstall ctypes followed by pip install ctypes. By following these steps systematically, users can address the 'ModuleNotFoundError: No module named '_ctypes'' issue in Python, resolving dependencies and ensuring the smooth functioning of the Python environment.
🌐
Itsourcecode
itsourcecode.com › home › modulenotfounderror: no module named _ctypes [fixed]
Modulenotfounderror: no module named _ctypes [Fixed] (2026)
July 12, 2026 - As the root cause is pretty simple in the same way the solution too. All we have to do is install or reinstall the libffi-dev package. Let’s get started. ... ‘ and possible causes of why this error occurs.
🌐
GitHub
github.com › yaml › pyyaml › issues › 742
" No module named '_ctypes'" when installing PyYAML 6.0.1 into Python 3.11.4 · Issue #742 · yaml/pyyaml
August 18, 2023 - File: /tmp/pip-req-build-cxvu7...-packages/wheel/macosx_libfile.py", line 43, in <module> import ctypes File "/usr/local/lib/python3.11/ctypes/__init__.py", line 8, in <module> from _ctypes import Union, Structure, Array ModuleNotFoundError: No module named '_ctypes' error: ...
Author: yaml
🌐
GitHub
github.com › oppia › oppia › issues › 14173
_ctypes not found and using python 3.9 gives an error · Issue #14173 · oppia/oppia
November 3, 2021 - Hello I am new to open source and am using an M1 mac and I have created a virtual env with python 3.7.10 as required however the installation gives an error when I use 3.7 it says that pyyaml is not found and when I try to install pyyaml, it says that _ctypes is not found. Now the trouble shooting page said that using 3.9 to do that bit works and while that is true running the start script with 3.9 gives an error No module named '_ctypes' No matching distribution found for coverage==5.3
Author: oppia
🌐
Stack Overflow
stackoverflow.com › questions › 70046501 › modulenotfounderror-no-module-named-ctypes-error-on-macos-big-sur-even-after
pip - ModuleNotFoundError: No module named '_ctypes' error on macOS Big Sur even after installing libffi - Stack Overflow
November 20, 2021 - Could not find a version that satisfies the requirement ctypes (from versions: ) No matching distribution found for ctypes ... python "ModuleNotFoundError: No module named '_ctypes'" error on a shared host (no ability to sudo install libffi-dev)
🌐
Stack Overflow
stackoverflow.com › questions › linked › 27022373
Hot Linked Questions - Stack Overflow
I try to launch a python file but it returns me the error: File "/usr/local/lib/python3.10/ctypes/init.py", line 8, in from _ctypes import Union, Structure, Array ModuleNotFoundError: No ...
🌐
Prefect
linen.prefect.io › t › 13089229 › i-have-an-install-issue-sweat-smile-in-thread
I have an install issue sweat smile In thread Prefect Community #pacc-july-6-2023
(test-prefect) ellawherritt@MacBook-Pro ...yenv/versions/3.11.1/lib/python3.11/ctypes/__init__.py", line 8, in <module> from _ctypes import Union, Structure, Array ModuleNotFoundError: No module named '_ctypes'...
🌐
Python.org
discuss.python.org › python help
Modul _ctypes not found - Python Help - Discussions on Python.org
August 9, 2024 - File “/usr/local/lib/python3.12/ctypes/init.py”, line 8, in from _ctypes import Union, Structure, Array ModuleNotFoundError: No module named ‘_ctypes’
🌐
GitHub
github.com › danhper › asdf-python › issues › 113
No module named '_ctypes' error for Python 3.7 with Mac Pro M1 · Issue #113 · asdf-community/asdf-python
September 22, 2021 - Hi, I installed python 3.7.12 with asdf. Then do pip3 install ansible throws error Collecting ansible Using cached ansible-4.6.0.tar.gz (35.6 MB) ERROR: Command errored out with exit status 1: comm...
Author: asdf-community