pythonmacossqlite3-python

How do I instruct Python to use my own compiled SQLite3?


I have compiled my own version of SQLite3 amalgamation tarball from the download page and would like to include that into my Python3 script on MacOs. Is there a way to do that via import sqlite3? As in, is it possible to instruct Python to use my own version?


Solution

  • pysqlite3 has Building a statically-linked library option

    To build pysqlite3 statically-linked against a particular version of SQLite, you need to obtain the SQLite3 source code and copy sqlite3.c and sqlite3.h into the source tree.

    # Download the latest release of SQLite source code and build the source
    # amalgamation files (sqlite3.c and sqlite3.h).
    $ wget https://www.sqlite.org/src/tarball/sqlite.tar.gz?r=release \
        -O sqlite.tar.gz
    $ tar xzf sqlite.tar.gz
    $ cd sqlite/
    $ ./configure
    $ make sqlite3.c
    
    # Copy the sqlite3 amalgamation files into the root of the pysqlite3 checkout
    # and run build_static + build:
    $ cp sqlite/sqlite3.[ch] pysqlite3/
    $ cd pysqlite3
    $ python setup.py build_static build
    

    You now have a statically-linked, completely self-contained pysqlite3.

    after above instructions you should be able to do

    from pysqlite3 import dbapi2 as sqlite3
    print(sqlite3.sqlite_version)
    

    which would reveal SQLite version used, as I do not have access to

    MacOs

    I am unable to test above approach, please try doing it yourself and write if it works.