Building a specific version of SQLite with pysqlite on macOS/Linux#
I wanted the ability to test my Python software against specific version of SQLite on macOS. I found a way to do that using pysqlite3.
First, clone the GitHub mirror of SQLite (so I don’t have to learn how to use Fossil):
1cd /tmp2git clone https://github.com/sqlite/sqlite
Check out the version tag you want to try:
1cd /tmp/sqlite2git checkout version-3.17.0
The SQLite build docs suggest using a bld
directory like this:
1mkdir /tmp/bld2cd /tmp/bld3../sqlite/configure4make sqlite3.c
This will have constructed the amalgamation source needed by pysqlite3
.
Now build that:
1cd /tmp2git clone https://github.com/coleifer/pysqlite33cd pysqlite34cp /tmp/bld/sqlite3.c .5cp /tmp/bld/sqlite3.h .6python3 setup.py build_static build
The end result sits in a pysqlite3
folder in, on my machine, /tmp/pysqlite3/build/lib.macosx-10.15-x86_64-3.9
- test it like this:
1cd /tmp/pysqlite3/build/lib.macosx-10.15-x86_64-3.92python33Python 3.9.6 (default, Jun 29 2021, 06:20:32)4[Clang 12.0.0 (clang-1200.0.32.29)] on darwin5Type "help", "copyright", "credits" or "license" for more information.6>>> import pysqlite37>>> pysqlite3.connect(":memory:").execute("select sqlite_version()").fetchone()[0]8'3.17.0'
Turn that into a wheel#
Running the following produces a wheel for the current platform that bundles the compiled .so
file:
1python3 setup.py bdist_wheel
On my machine that created /tmp/pysqlite3/dist/pysqlite3-0.4.6-cp39-cp39-macosx_10_15_x86_64.whl
.
Having created that file, running this in any virtual enviroment installed my custom build of pysqlite3
with the correct SQLite version:
1pip install /tmp/pysqlite3/dist/pysqlite3-0.4.6-cp39-cp39-macosx_10_15_x86_64.whl
This exact same process works on Linux too (tested inside a default GitHub Actions Linux worker).