Sqlite3 Error

Introduction #

On some operating systems (e.g., CentOS 7), running SmartChart with SQLite3 may encounter version incompatibility errors. This is because the system’s built-in SQLite3 version is too low — Django requires SQLite 3.8.3 or later.

Error Message #

django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17).

Solution Comparison #

Solution Difficulty Use Case Recommended
Upgrade system SQLite3 Medium General Good
Use pysqlite3 replacement Simple Quick fix Best

Solution 1: Upgrade System SQLite3 #

From StackOverflow:

  1. Download new SQLite3 version:
wget https://www.sqlite.org/2019/sqlite-autoconf-3290000.tar.gz
  1. Extract:
tar zxvf sqlite-autoconf-3290000.tar.gz
  1. Enter directory:
cd sqlite-autoconf-3290000
  1. Configure install path:
./configure --prefix=$HOME/opt/sqlite
  1. Build and install:
make && make install
  1. Set environment variables:
export PATH=$HOME/opt/sqlite/bin:$PATH
export LD_LIBRARY_PATH=$HOME/opt/sqlite/lib
export LD_RUN_PATH=$HOME/opt/sqlite/lib

Verify with sqlite3 --version.

If upgrading system SQLite3 still fails, use this quick fix:

# Install
pip3 install pysqlite3
pip3 install pysqlite3-binary

# Edit Django's file (path shown in error message)
vi xxxxxx/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py
# Change:
# from sqlite3 import dbapi2 as Database  # Comment this out
from pysqlite3 import dbapi2 as Database

# Save and exit: :wq!