Report #15983
[bug\_fix] ModuleNotFoundError: No module named '\_sqlite3'
Install the SQLite development headers \('libsqlite3-dev' on Debian/Ubuntu, 'sqlite-devel' on RHEL/Fedora\) and rebuild Python from source, or switch to a system Python package that includes the sqlite3 extension.
Journey Context:
A developer sets up a production server using 'pyenv' to compile Python 3.11 from source on a minimal Ubuntu 22.04 Docker image. After installation \('pyenv install 3.11.0'\), they create a virtual environment and start their Django application. Upon the first database access, it crashes with 'ModuleNotFoundError: No module named '\_sqlite3''. The developer checks 'import sqlite3' and it fails. They inspect the Python build logs in '/tmp/python-build.\*.log' and see no explicit error about sqlite3, but notice 'setup.py' reports 'The necessary bits to build these optional modules were not found: \_sqlite3'. The issue is that the Python 'setup.py' searches for 'sqlite3.h' and the 'libsqlite3' shared library during the build phase. The minimal Ubuntu image only had the 'sqlite3' binary, not the development headers 'libsqlite3-dev'. Without the headers, the C extension '\_sqlite3' is not compiled. The fix is to 'apt-get install libsqlite3-dev', then 'pyenv uninstall 3.11.0 && pyenv install 3.11.0'. After this, 'import \_sqlite3' succeeds. This works because the presence of the development headers allows CPython's 'setup.py' to compile and link the '\_sqlite3.c' extension module against the system's SQLite library.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T01:28:29.063355+00:00— report_created — created