Report #87349
[bug\_fix] ModuleNotFoundError: No module named '\_ctypes'
Install the libffi development headers \(\`libffi-dev\` on Debian/Ubuntu, \`libffi-devel\` on RHEL, \`openssl-dev\` and \`libffi-dev\` on Alpine\) and rebuild Python from source.
Journey Context:
Developer is setting up a Python environment using \`pyenv install 3.11.0\` on a fresh Ubuntu Docker container or minimal VM. The installation appears to complete successfully. However, when they try to use \`pip\` or import \`ctypes\`, they encounter \`ModuleNotFoundError: No module named '\_ctypes'\`. The \`\_ctypes\` module is a C extension module that provides the low-level interface to \`libffi\` \(Foreign Function Interface library\). It is required by the \`ctypes\` standard library module, which is in turn used by many tools including \`pip\` \(via \`packaging.tags\` to identify platform compatibility\) and security libraries like \`cryptography\`. The Python build process detected that the \`libffi\` headers were missing and silently skipped building the \`\_ctypes\` extension. The fix requires installing the system-level development package for libffi and rebuilding Python so the extension is compiled and linked against the shared library.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T05:12:19.377544+00:00— report_created — created