How to compile sqlite3 and upgrade its version in python

In the example below I have an ubuntu 18.04 where I need to upgrade sqlite3 v3.22 version to something bigger than v3.35.4 so I can make use of math functions like: acos(X), acosh(X), asin(X), asinh(X), atan(X), atan2(Y,X), atanh(X), ceil(X), ceiling(X), cos(X), cosh(X), degrees(X), exp(X), floor(X), ln(X), log(B,X), log(X), log10(X), log2(X), mod(X,Y), pi(), pow(X,Y), power(X,Y), radians(X), sin(X), sinh(X), sqrt(X), tan(X), tanh(X), trunc(X)

First of all check your current version of sqlite

root@01617137c09f:~# sqlite3 --version
3.22.0 2018-01-22 18:45:57 0c55d179733b46d8d0ba4d88e01a25e10677046ee3da1d5b1581e86726f2alt1

root@01617137c09f:~# python3 -c "import sqlite3;print(sqlite3.sqlite_version);print(sqlite3.__file__)"
3.22.0Code language: PHP (php)

If you have sqlite installed by apt then uninstall it

root@01617137c09f:~# apt remove sqlite3Code language: PHP (php)

Download & unpack newest sqlite-autoconf from sqlite.org download page

root@01617137c09f:~# wget https://www.sqlite.org/2022/sqlite-autoconf-3390400.tar.gz
root@01617137c09f:~# tar -zxvf sqlite-autoconf-3390400.tar.gzCode language: PHP (php)

Then compile sqlite3 and install system wide
(for this step you might need to install build-essential package on ubuntu or a set of packages on other systems)

root@01617137c09f:~# apt install <span style="background-color: inherit; font-family: inherit; font-size: inherit; white-space: pre-wrap; color: initial;">build-essential</span>

root@01617137c09f:~# cd sqlite-autoconf-3390400
root@01617137c09f:~/sqlite-autoconf-3390400# ./configure
root@01617137c09f:~/sqlite-autoconf-3390400# make
root@01617137c09f:~/sqlite-autoconf-3390400# make installCode language: PHP (php)

After this you’ll see no sqlite3 and old sqlite3 inside python. You’ll need to restart terminal to see newer version of system sqlite3 package

root@01617137c09f:~# sqlite3 --version
bash: /usr/bin/sqlite3: No such file or directory

root@01617137c09f:~# python3 -c "import sqlite3;print(sqlite3.sqlite_version);print(sqlite3.__file__)"
3.22.0



root@01617137c09f:~# bash

root@01617137c09f:~# sqlite3 --version
3.39.4 2022-09-29 15:55:41 a29f9949895322123f7c38fbe94c649a9d6e6c9cd0c3b41c96d694552f26b309

root@01617137c09f:/sqlite-autoconf-3390400# python3 -c "import sqlite3;print(sqlite3.sqlite_version);print(sqlite3.__file__)"
3.22.0Code language: PHP (php)

Now just reinstall python (I’m not sure which package exactly needs to be reinstalled)

root@01617137c09f:~# apt -y remove python3
root@01617137c09f:~# apt -y autoremove
root@01617137c09f:~# apt -y install python3Code language: PHP (php)

Again check your sqlite versions, voila!

root@01617137c09f:/sqlite-autoconf-3390400# sqlite3 --version
3.39.4 2022-09-29 15:55:41 a29f9949895322123f7c38fbe94c649a9d6e6c9cd0c3b41c96d694552f26b309

root@01617137c09f:/sqlite-autoconf-3390400# python3 -c "import sqlite3;print(sqlite3.sqlite_version);print(sqlite3.__file__)"
3.39.4Code language: PHP (php)

Leave a Reply

Your email address will not be published. Required fields are marked *