Skip to content

Instantly share code, notes, and snippets.

@defulmere
Last active May 15, 2025 03:27
Show Gist options
  • Save defulmere/8b9695e415a44271061cc8e272f3c300 to your computer and use it in GitHub Desktop.
Save defulmere/8b9695e415a44271061cc8e272f3c300 to your computer and use it in GitHub Desktop.
How to override an old sqlite3 module with pysqlite3 in django settings.py
# ⚠️ USE AT YOUR OWN RISK
# first: pip install pysqlite3-binary
# then in settings.py:
# these three lines swap the stdlib sqlite3 lib with the pysqlite3 package
__import__('pysqlite3')
import sys
sys.modules['sqlite3'] = sys.modules.pop('pysqlite3')
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
@sdubal
Copy link

sdubal commented Nov 14, 2024

thanks, worked for me.

@JGallegoPerez
Copy link

import('pysqlite3')
import sys
sys.modules['sqlite3'] = sys.modules.pop('pysqlite3')

Worked perfectly for me too.

@AlbertoMQ
Copy link

This gives the error
NameError: name 'sqlite3' is not defined

import('pysqlite3')
import sys
sys.modules['sqlite3'] = sys.modules.pop('pysqlite3')

@subhammoda
Copy link

Hi, I tried the solutions above, I have pysqlite3-binary in requirements.txt. I have added the following to the streamlit_app.py code. I am on Python version 3.10.15. I have sqlite 3.43.2 available on my mac.

__import__('pysqlite3') import sys sys.modules['sqlite3'] = sys.modules.pop('pysqlite3')

But the following gives me the error of "No module named 'pysqlite3'"

Running pip install pysqlite3 is unsuccessful, giving the error "ERROR: Failed to build installable wheels for some pyproject.toml based projects (pysqlite3)"

Can someone help. I face the issue when trying to deploy the app on streamlit. It worked perfectly for me on the local.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment