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

[email protected]01617137c09f:~# sqlite3 --version 3.22.0 2018-01-22 18:45:57 0c55d179733b46d8d0ba4d88e01a25e10677046ee3da1d5b1581e86726f2alt1 [email protected]01617137c09f:~# python3 -c "import sqlite3;print(sqlite3.sqlite_version);print(sqlite3.__file__)" 3.22.0
Code language: PHP (php)

If you have sqlite installed by apt then uninstall it

[email protected]01617137c09f:~# apt remove sqlite3
Code language: PHP (php)

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

[email protected]01617137c09f:~# wget https://www.sqlite.org/2022/sqlite-autoconf-3390400.tar.gz [email protected]01617137c09f:~# tar -zxvf sqlite-autoconf-3390400.tar.gz
Code 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)

[email protected]01617137c09f:~# apt install <span style="background-color: inherit; font-family: inherit; font-size: inherit; white-space: pre-wrap; color: initial;">build-essential</span> [email protected]01617137c09f:~# cd sqlite-autoconf-3390400 [email protected]01617137c09f:~/sqlite-autoconf-3390400# ./configure [email protected]01617137c09f:~/sqlite-autoconf-3390400# make [email protected]01617137c09f:~/sqlite-autoconf-3390400# make install
Code 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

[email protected]01617137c09f:~# sqlite3 --version bash: /usr/bin/sqlite3: No such file or directory [email protected]01617137c09f:~# python3 -c "import sqlite3;print(sqlite3.sqlite_version);print(sqlite3.__file__)" 3.22.0 [email protected]01617137c09f:~# bash [email protected]01617137c09f:~# sqlite3 --version 3.39.4 2022-09-29 15:55:41 a29f9949895322123f7c38fbe94c649a9d6e6c9cd0c3b41c96d694552f26b309 [email protected]01617137c09f:/sqlite-autoconf-3390400# python3 -c "import sqlite3;print(sqlite3.sqlite_version);print(sqlite3.__file__)" 3.22.0
Code language: PHP (php)

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

[email protected]01617137c09f:~# apt -y remove python3 [email protected]01617137c09f:~# apt -y autoremove [email protected]01617137c09f:~# apt -y install python3
Code language: PHP (php)

Again check your sqlite versions, voila!

[email protected]01617137c09f:/sqlite-autoconf-3390400# sqlite3 --version 3.39.4 2022-09-29 15:55:41 a29f9949895322123f7c38fbe94c649a9d6e6c9cd0c3b41c96d694552f26b309 [email protected]01617137c09f:/sqlite-autoconf-3390400# python3 -c "import sqlite3;print(sqlite3.sqlite_version);print(sqlite3.__file__)" 3.39.4
Code language: PHP (php)

Leave a Reply

Your email address will not be published.