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 OverflowInstalling 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
If you use pyenv and get error "No module named '_ctypes'" (like i am) on Debian/Raspbian/Ubuntu you need to run this commands:
sudo apt-get install libffi-dev
pyenv uninstall 3.7.6
pyenv install 3.7.6
Put your version of python instead of 3.7.6
Modul _ctypes not found
ImportError : No module named '_ctypes'
" No module named '_ctypes'" when installing PyYAML 6.0.1 into Python 3.11.4
python - Accessing arrays inside ctypes union - Stack Overflow
Take a look at the ctypes tutorial. You use the ctypes.Union class:
class test(ctypes.Structure):
# ...
class test2(ctypes.Structure):
# ...
class tests(ctypes.Union):
_fields_ = [("a", test),
("b", test2)]
Simply create a class that inherits from ctypes.Union.
Read more about it here.
You then define the union fields in the _fields_ class member.
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
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