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 Overflow
🌐
Python
docs.python.org › 3 › library › ctypes.html
ctypes — A foreign function library for Python
The field type must be a ctypes type like c_int, or any other derived ctypes type: structure, union, array, pointer. Here is a simple example of a POINT structure, which contains two integers named x and y, and also shows how to initialize a structure in the constructor: >>> from ctypes import * ...
Discussions

Modul _ctypes not found
File “/usr/local/lib/python3.12/ctypes/init.py”, line 8, in from _ctypes import Union, Structure, Array ModuleNotFoundError: No module named ‘_ctypes’ More on discuss.python.org
🌐 discuss.python.org
6
0
August 9, 2024
" No module named '_ctypes'" when installing PyYAML 6.0.1 into Python 3.11.4
File: /tmp/pip-req-build-cxvu7... import ctypes File "/usr/local/lib/python3.11/ctypes/__init__.py", line 8, in from _ctypes import Union, Structure, Array ModuleNotFoundError: No module named '_ctypes' error: subprocess-exited-with-error × Preparing metadata ... More on github.com
🌐 github.com
5
August 18, 2023
ImportError : No module named '_ctypes'
Environment Pythonnet version: 2.3.0.0 Python version: 3.5.4 Operating System: Windows 10 Pro Version 1803 I am trying to use Python.NET to perform interop between C# and Python on a Windows machin... More on github.com
🌐 github.com
5
August 4, 2019
Building python error "No module named '_ctypes'"
Hi, I'm have never used ASDF but I found some post on stackoverflow that may help you. It suggest to install the package libffi-devel first. This can be done from the void repository. The full post is here: https://stackoverflow.com/questions/27022373/python3-importerror-no-module-named-ctypes-when-using-value-from-module-mul More on reddit.com
🌐 r/voidlinux
2
4
May 14, 2019
🌐
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’
🌐
Python
docs.python.org › 2.5 › lib › ctypes-structures-unions.html
14.14.1.10 Structures and unions
December 23, 2008 - The field type must be a ctypes type like c_int, or any other derived ctypes type: structure, union, array, pointer. Here is a simple example of a POINT structure, which contains two integers named x and y, and also shows how to initialize a structure in the constructor: >>> from ctypes import * ...
🌐
Cdotson
cdotson.com › 2015 › 05 › c-style-unions-and-python
C-Style Unions And Python – Chad Dotson
Second, its faster to pull in arrays in python than single values. Using ctypes, you can approach a functionality similar C. Take the following code for example. from ctypes import c_int, c_uint, c_float, Union from struct import unpack class MyType(Union): _fields_ = [("i", c_int), ("u", c_uint), ("f", c_float)] var = MyType() var.i = unpack("i", byte_buffer)[0] # then var.i, var.u, var.f contain the integer, unsigned int, and float representations respectively.
🌐
Readthedocs
rawkit.readthedocs.io › en › latest › _modules › ctypes.html
ctypes — rawkit 0.6.0 documentation
"""create and manipulate C data types in Python""" import os as _os, sys as _sys __version__ = "1.1.0" from _ctypes import Union, Structure, Array from _ctypes import _Pointer from _ctypes import CFuncPtr as _CFuncPtr from _ctypes import __version__ as _ctypes_version from _ctypes import ...
🌐
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... 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: subprocess-exited-with-error × Preparing metadata ...
Author: yaml
Find elsewhere
🌐
GitHub
github.com › pythonnet › pythonnet › issues › 932
ImportError : No module named '_ctypes' · Issue #932 · pythonnet/pythonnet
August 4, 2019 - [' File "C:\\Python\\3_5_4\\Lib\\site-packages\\numpy\\__init__.py", line 140, in <module>\n from . import _distributor_init\n', ' File "C:\\Python\\3_5_4\\Lib\\site-packages\\numpy\\_distributor_init.py", line 9, in <module>\n from ctypes import WinDLL\n', ' File "C:\\Python\\3_5_4\\Lib\\ctypes\\__init__.py", line 8, in <module>\n from _ctypes import Union, Structure, Array\n']
Author: pythonnet
🌐
Reddit
reddit.com › r/voidlinux › building python error "no module named '_ctypes'"
r/voidlinux on Reddit: Building python error "No module named '_ctypes'"
May 14, 2019 -

Trying to install python 3.7.1 (Have reproduced this error by trying versions 3.5.1 -> 3.7.2) with ASDF version manager (It builds runtimes, interpreters, etc. from source) and the build process will error out saying its missing a ctypes module, full log below. I have successfully, built and installed golang and ruby with ASDF.

Full python-build log

BUILD FAILED (VoidLinux rolling using python-build 1.2.11-11-g7dd50144)

Inspect or clean up the working tree at /tmp/python-build.20190514124804.6862
Results logged to /tmp/python-build.20190514124804.6862.log

Last 10 log lines:
    import pip._internal
  File "/tmp/tmpvo5m0eed/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/__init__.py", line 42, in <module>
  File "/tmp/tmpvo5m0eed/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/cmdoptions.py", line 16, in <module>
  File "/tmp/tmpvo5m0eed/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/index.py", line 25, in <module>
  File "/tmp/tmpvo5m0eed/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/download.py", line 39, in <module>
  File "/tmp/tmpvo5m0eed/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/utils/glibc.py", line 3, in <module>
  File "/tmp/python-build.20190514124804.6862/Python-3.7.1/Lib/ctypes/__init__.py", line 7, in <module>
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
make: *** [Makefile:1122: install] Error 1
🌐
Reddit
reddit.com › r/learnpython › help - importerror: no module named '_ctypes'
r/learnpython on Reddit: Help - ImportError: No module named '_ctypes'
August 3, 2022 - Traceback (most recent call last): ... < module> import ctypes File "/usr/local/lib/python3.4/ctypes/init.py", line 7, in <module> from _ctypes import Union, Structure, Array ImportError: No module named '_ctypes'...
🌐
GitHub
github.com › pypa › pipenv › issues › 4901
mac m1 python3.7 ModuleNotFoundError: No module named '_ctypes' · Issue #4901 · pypa/pipenv
December 26, 2021 - 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)... Locking [dev-packages] dependencies...
Author: pypa
🌐
Rose-Hulman Institute of Technology
rose-hulman.edu › Class › csse › archive › csse120-old › csse120-old-terms › 201110robotics › Resources › python-3.1.2-docs-html › _sources › library › ctypes.txt
ctypes.txt
:attr:`_fields_` must be a list of *2-tuples*, containing a *field name* and a *field type*. The field type must be a :mod:`ctypes` type like :class:`c_int`, or any other derived :mod:`ctypes` type: structure, union, array, pointer. Here is a simple example of a POINT structure, which contains two integers named *x* and *y*, and also shows how to initialize a structure in the constructor:: >>> from ctypes import * >>> class POINT(Structure): ...
🌐
NVIDIA
docs.nvidia.com › deeplearning › tensorrt › 10.x.x › _static › polygraphy › _modules › ctypes.html
ctypes - Polygraphy0.49.24
"""create and manipulate C data types in Python""" import os as _os, sys as _sys import types as _types __version__ = "1.1.0" from _ctypes import Union, Structure, Array from _ctypes import _Pointer from _ctypes import CFuncPtr as _CFuncPtr from _ctypes import __version__ as _ctypes_version ...
🌐
GitHub
github.com › MycroftAI › mycroft-core › issues › 1979
Installer Python script/s fail. -- No module named '_ctypes'. · Issue #1979 · MycroftAI/mycroft-core
February 2, 2019 - % Total % Received % Xferd Average ... line 3, in <module> File "/usr/local/lib/python3.7/ctypes/__init__.py", line 7, in <module> from _ctypes import Union, Structure, Array ModuleNotFoundError: No module named '_ctypes' Failed to set up virtualenv for mycroft, exiting ...
Author: MycroftAI
🌐
Reddit
reddit.com › r/learnpython › compiling python error: _ctypes not found
r/learnpython on Reddit: Compiling Python error: _ctypes not found
May 14, 2019 -

I downloaded the Python-3.7.0 tar file from python.org, and I'm following the directions in the README.rst file. I did the ./configure, which worked, then make test, and that returned SUCCESS, but now when I run then sudo make install it runs for about 20 seconds until it runs a python script that imports _ctypes as which point the below stack trace is generated. Python is there, and when I type python3, it opens python3.7 which seems to mean that everything compiled properly, so I have no idea why the ctypes module is missing. I'm pretty new to compiling my own software so if you see any other mistakes feel free to point them out :D

Thanks

Traceback (most recent call last):
File "/home/toss/Python-3.7.0/Lib/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
File "/home/toss/Python-3.7.0/Lib/runpy.py", line 85, in _run_code
    exec(code, run_globals)
File "/home/toss/Python-3.7.0/Lib/ensurepip/__main__.py", line 5, in <module>
    sys.exit(ensurepip._main())
File "/home/toss/Python-3.7.0/Lib/ensurepip/__init__.py", line 204, in _main
    default_pip=args.default_pip,
File "/home/toss/Python-3.7.0/Lib/ensurepip/__init__.py", line 117, in _bootstrap
    return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
File "/home/toss/Python-3.7.0/Lib/ensurepip/__init__.py", line 27, in _run_pip
    import pip._internal
File "/tmp/tmpwul0zw99/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/__init__.py", line 42, in <module>
File "/tmp/tmpwul0zw99/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/cmdoptions.py", line 16, in <module>
File "/tmp/tmpwul0zw99/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/index.py", line 25, in <module>
File "/tmp/tmpwul0zw99/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/download.py", line 39, in <module>
File "/tmp/tmpwul0zw99/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/utils/glibc.py", line 3, in <module>
File "/home/toss/Python-3.7.0/Lib/ctypes/__init__.py", line 7, in <module>
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
Makefile:1122: recipe for target 'install' failed
make: [install] Error 1 (ignored)

Edit: Turns out I was missing a few external libraries. installing the following packages resolved my issue:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus
sudo apt-get install libncursesw5-dev libgdbm-dev libc6-dev
sudo apt-get install zlib1g-dev libsqlite3-dev tk-dev
sudo apt-get install libssl-dev openssl
sudo apt-get install libffi-dev 
🌐
GitHub
github.com › P0cL4bs › wifipumpkin3 › issues › 64
_ctypes Module not found · Issue #64 · P0cL4bs/wifipumpkin3
July 18, 2020 - """create and manipulate C data types in Python""" import os as _os, sys as _sys __version__ = "1.1.0" from _ctypes import Union, Structure, Array from _ctypes import _Pointer from _ctypes import CFuncPtr as _CFuncPtr from _ctypes import __version__ as _ctypes_version from _ctypes import RTLD_LOCAL, RTLD_GLOBAL from _ctypes import ArgumentError ``
Author: P0cL4bs