Python (Scripting) - Resolve "No module named '_ctypes'"
by
Jeremy Canfield |
Updated: November 15 2023
| Python (Scripting) articles
Let's say something like this is being returned.
No module named '_ctypes'
I could reproduce this by running Python with the -m ctypes option.
~]# /usr/local/bin/python3.10.2/bin/python3.10 -m ctypes
Traceback (most recent call last):
File "/usr/local/bin/python3.10.2/lib/python3.10/runpy.py", line 187, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/usr/local/bin/python3.10.2/lib/python3.10/runpy.py", line 146, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "/usr/local/bin/python3.10.2/lib/python3.10/runpy.py", line 110, in _get_module_details
__import__(pkg_name)
File "/usr/local/bin/python3.10.2/lib/python3.10/ctypes/__init__.py", line 8, in <module>
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes
I got this after installing Python from source and my system did not contain the libffi-dev or libffi-devel package.
]# yum list installed | grep libffi
libffi.x86_64 3.0.13-19.el7 @rhel-7-server-rpms
I resolved this by first installing the libffi-devel package.
dnf install libffi-devel
And validated the libffi-devel package was installed.
~]# yum list installed | grep libffi
libffi.x86_64 3.0.13-19.el7 @rhel-7-server-rpms
libffi-devel.x86_64 3.0.13-19.el7 @rhel-7-server-rpms
Then I reinstalled Python from source and I no longer got the error.
Did you find this article helpful?
If so, consider buying me a coffee over at