How to use the latest sqlite3 version in python How to use the latest sqlite3 version in python sqlite sqlite

How to use the latest sqlite3 version in python


Option 1: Use the binary version of pysqlite3 from here (which already comes with a newer version of sqlite3 lib precompiled and linked):https://github.com/coleifer/pysqlite3.Basically install with

pip install pysqlite3-binary

and in python code, use pysqlite3 instead of sqlite3 like:

import pysqlite3    (...) conn = pysqlite3.connect(r"filename")

Alternative:Reinstall python, when installing python, a built in python's module sqlite3 (for working with sqlite) is compiling and uses (compiles) its own version of sqlite3 lib regardless of what you currently have in your system (this is the case at least on windows and mac systems, may be also the case for unix based systems).


Two ideas...

  1. Use pyenv to install a separate interpreter, and provide the path to the newer sqlite when creating it. eg:

    PYTHON_CONFIGURE_OPTS="LD_RUN_PATH=/usr/local/opt/sqlite/lib LDFLAGS=-L/usr/local/opt/sqlite/lib CPPFLAGS=-I/usr/local/include" pyenv install 3.4.3

    This pyenv issue provides some more details/ideas.

  2. APSW provides an up to date implementation of SQLite, but has different goals from the pysqlite library.

    APSW provides an SQLite 3 wrapper that provides the thinnest layer over the SQLite database library possible. Everything you can do from the SQLite C API, you can do from Python. Although APSW looks vaguely similar to the PEP 249 (DBAPI), it is not compliant with that API because instead it works the way SQLite 3 does. (pysqlite is DBAPI compliant - see the differences between apsw and pysqlite 2).

    APSW embeds the SQLite "amalgamation" distribution statically, so you can safely use it in an environment (eg. Python) which might also have another SQLite loaded.


There's unofficial Python wheel distribution of APSW which itself doesn't release on PyPI:

APSW is not available at the Python Package Index (pypi) and hence cannot be installed from it. (A random person has put an outdated poor quality upload under the APSW name. It has nothing useful to do with this project.) The reason for this is [...]

And I assume the reason predates Python wheels.

The wheel distribution package is called apsw-wheels (and GitHub repo). It worked just fine for me except for PyPy wheels.