paketo-buildpacks / cpython

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compiled python executables do not provide `_sqlite3` module

matthiaswenz opened this issue · comments

Expected Behavior

I can import the sqlite3 module in a Python application with the cpython provided from this buildpack.

Current Behavior

I get an error telling me the underlying required module is not available:

Python 3.10.7 (main, Dec  2 2022, 17:14:18) [GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/workspaces/bionic/python_sans_sqlite/lib/python3.10/sqlite3/__init__.py", line 57, in <module>
    from sqlite3.dbapi2 import *
  File "/workspaces/bionic/python_sans_sqlite/lib/python3.10/sqlite3/dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'

Possible Solution

Install libsqlite3-dev on the builder when compiling Python should fix this, proposed in #478

Steps to Reproduce

  1. Build a sample python app
  2. Create an image i.e. using pack CLI: pack build <my-app> --builder=paketobuildpacks/builder-jammy-full full builder optional but the running stack should have sqlite available which I believe is only true on the full image.
  3. Start up your container e.g. into the default entrypoint as the python prompt: docker run -it <my-app>
  4. In the prompt run import sqlite3
  5. Observe the above result

Motivations

I ran into this issue running a python sample application, found recommendations to use the full builder but that didn't solve it for me.